1

I see that apps like facebook for example are getting push notifications in real time. When someone writes a message to me from a pc ill get the message to my android device as push notification just a second later even when my facebook app is not running.

Im wondering how it works because for my app i need a quite similar behaviour. There is also a messaging and an alert mechanism between server and client but i cant imagine how i could implement it so that i can get real time updates from the server to the client even when the app is not started.

Does someone know?

Mulgard
  • 9,877
  • 34
  • 129
  • 232

1 Answers1

6

Yes, use Sync Adapter with GCM (Google Cloud Messaging) :

http://developer.android.com/training/sync-adapters/index.html

Read the tutorial i provided, you will at least know what to use.

And check this SO question, it has good answers (especially the accepted one) :

Sync data between Android App and webserver

Community
  • 1
  • 1
Blaze Tama
  • 10,828
  • 13
  • 69
  • 129
  • [Note:](https://developer.android.com/training/sync-adapters/index.html) Sync adapters run asynchronously, so you should use them with the expectation that they transfer data regularly and efficiently, but not instantaneously. If you need to do real-time data transfer, you should do it in an AsyncTask or an IntentService. – Pratik Butani Aug 04 '16 at 05:58