Manish
Manish

Reputation: 3968

Ideal Polling Mechanism/Interval for Android client/server application

I am planning to implement a chat application in Android, and need to make a few design decisions related to polling the server for updates:

  1. How often should I poll for new messages? Will polling every minute be a good choice?

  2. How can real time chat be supported? Should the polling be done every 5 seconds in case the user sends message and then return to long polling interval in case no new message is received?

I also need to make sure the application does not drain the battery quickly. I need to design the application on similar lines as WhatsApp. I am not sure how does it manage polling, but I know its not a battery killer.

Upvotes: 1

Views: 2527

Answers (4)

Benito Bertoli
Benito Bertoli

Reputation: 25793

You should look into XMPP.

WhatsApp uses a modified version of XMPP.

Here's a tutorial to get started.

Upvotes: 3

Ivan
Ivan

Reputation: 713

  1. For avoiding to be a battery killer, you should stop the loop for polling when screen off, or make the interval to be very long when screen off
  2. Maybe you can keep a long lived connection to make a real time chat.
  3. Using GCM is a better choice

Upvotes: 0

Birdy
Birdy

Reputation: 355

For the chat I'd make two different kind of polling. First if the application is in background (every minute or something like this) and if the app is started every second or maybe long polling: http://en.wikipedia.org/wiki/Push_technology#Long_polling

Upvotes: 0

Lionel Port
Lionel Port

Reputation: 3542

Polling is not the answer for this type of application. If your application is solely Android base you should look at the Google Cloud Messaging Framework (http://developer.android.com/google/gcm/index.html).

This allows you to push messages to individual clients over xmpp (or http ping to pull). This way they can get updates almost instantly.

Upvotes: 0

Related Questions