Reputation: 61
I found an instant messaging apk demo and inside I found the TimerTask library . The original developer used it to update the conversations list and friends list.
private final int UPDATE_TIME_PERIOD = 15000;
My question is:Is this a good practice? Because 15000 its not really live application.
Example if I send a message just after timertask run the receiver need to wait 15000ms.Thank you!
Upvotes: 3
Views: 96
Reputation: 4136
Using update_time_period as 15 secs is definitely not a good idea.If you are building a chat application, you should base it on XMPP protocol. This is different than using HttpUrlConnection to poll messages, in XMPP protocol a connection is kept live as long as the user is logged in, so you can envision once a user opens the app he establishes a connection and keeps it alive unless he logs out and the server can keep sending data to the client. this is how most of the chat apps function. To start integrating this functionality in your app and learn more about this, i would recommend reading on Smack and probably check out this repository.
To make starting things up more quickly you can checkout firebase and firebase based realtime chatbased app. Firebase is pretty cool.
Upvotes: 1