3

Apps like twitter drain phone's battery quickly as it have to wake up the phone when a new tweet comes. My app need constant connection to server. It won't download or upload data constantly.sending TCP keep-alive every 2 minutes can save battery life or the only way we can talk to server constantly is by push notifications? why push itself doesn't drain battery?

  • 1
    TCP approach is good and send data to the server only when its necessary, and GCM is used to notify the user of something that happend, if someone just wrote in a chat group or something similar. It depends on what type of application are you developing. – cesztoszule Mar 24 '14 at 15:25
  • TCP approach won't drain battery? if not then why we need gcm? – user3455628 Mar 24 '14 at 17:47

1 Answers1

1

If you want to implement something like this you could use Google Cloud Messaging:

http://developer.android.com/google/gcm/gcm.html

Basically you create Google API project that sends information to Google Cloud Messaging Server. This server queues your messages and send them to the final device when it's able to receive them. Your device already keeps an open socket at all times to receive these messages so there's not a big impact on battery drain.

ordago
  • 377
  • 3
  • 20
  • can we make our own gcm ? – user3455628 Mar 24 '14 at 17:45
  • 1
    I guess you could implement something similiar, keeping an open socket at all times or at some periods of time. But unless you modify the Android code yourself and every user of your app has this modified Android version, you'll have two open sockets so you'll still drain battery. If I were you I'll try to use GCM and not implementing something that is already implemented, will drain more battery, will probably need more permissions, users will need their phone rooted... – ordago Mar 31 '14 at 11:15