Sorry for asking a question, that already asked for many times, i think, (also checked Questions that may already have your answer) but i don not know better solution, what to do.
I have written SMS Application on Android (Client) and PHP/Mysql/Kannel (Server) that simply sends and receives messages. It looks like simple solution, but when i first started bug test, found out, that it is very slow and kills memory usage. This is the first time for me, creating strong application. I'm using Volley, of course.
private List<ConversationsModel> conversationsList = new ArrayList<ConversationsModel>();
ConversationsRequest = MainPageActivity.instance().ConversationsRequest(ConversationURL, mPullToRefreshLayout);
MainController.getInstance().addToRequestQueue(ConversationsRequest);
conversationsList.clear();
ArrayList<HashMap<String, String>> lastMessages = db.getLastMessages("");
PrettyTime p = new PrettyTime();
for (HashMap<String, String> map : lastMessages) {
SimpleDateFormat fmt = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date date;
ConversationsModel convModel = new ConversationsModel();
try {
date = fmt.parse(map.get("vsenderdate"));
convModel.setSenddate(p.format(date).toString());
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
convModel.setLasttext(map.get("vlasttext"));
convModel.setNum(map.get("vphonenumber"));
convModel.setThumbnailUrl(map.get("vprofilepic"));
convModel.setUnread(Integer.parseInt(map.get("vunread")));
convModel.setUsernameornumber(map.get("vcontact"));
convModel.setUniqueid(map.get("vuniqueid"));
if (map.get("vuniqueid").equals("0")) {
convModel.setIsgroup(0);
} else {
convModel.setIsgroup(1);
}
conversationsList.add(convModel);
adapter.notifyDataSetChanged();
}
php side is simple json
{"contact":{"name":"+xxx xxx xxx xxx"},"contact_image":"image.png","uniqueid":"0","num":"xxx xxx xxx","lasttext":"text goes here...","lastdate":"2015-01-21 12:13:59","unread":0}
I do not want examples how to code. This is simple model that runs inside thread with 30 seconds interval, gets json data, then I clear sQlite database and insert new rows, at least application reads from sQlite database.
When I saw that it was very simple, slow and ugly solution, I made Crontab that retrieves same json data from mysql and stores in .json file. I read data from json file, not directly from database. I became faster, but still killing application.
now I'm going to create some simple web server in C++, that connect to xxx port and gets data. But I think it is not better solution at all. Is there better solution? Should I get data in bytes to make faster or what can I do to application, to exchange data faster between client and server.
Thanks in advanced.
Aucun commentaire:
Enregistrer un commentaire