I have been trying to develop an android app like whatsapp, hike, etc....
I'm using SQLITE DATABASE to store messages local including images byte-codes.
I'm using the Runnable Handler with postDelayed() method of 3 seconds, which means every 3 seconds, the application connects with server for new messages and status be drawn, updated in listView and saved in sqllite database.
Now I'm facing trouble if the number of incoming messages are more say 150-200 messages.... the handler re-launch the code before the previous all 150 messages stored in database.
handler = new Handler();
handler.post(runnableCode);
Runnable runnableCode = new Runnable() {
@Override
public void run() {
if (check.check(1)) { //Check for Network Connection
asyncExecute = false;
getNewMessages(); //Calling method of asynctask for New Messages
}
handler.postDelayed(this, 3000); //Run this every 3 seconds
}
};
So, what I want is, till all my messages get saved in database and images downloaded completed, the handler should not be called. After saved and downloaded fully, the next handler should be called.
Tell me the best way to achieve this.
Aucun commentaire:
Enregistrer un commentaire