java - How to send data to an Android app from a web server? -
Assume that I want to create messaging app like WhatsApp or Viber to send messages, transfer messages from user A to server Has been done and should be transferred from server to user B. The question is how can User B find out that there is a new message on its server? One solution is to check every other server for new messages; However this solution will cause performance issues.
What is the best solution to this problem? How to send data from the web server to the Android app periodically without the need of the server?
Some clues about which I need to use classes or techniques and / or some sample code would be greatly appreciated. Thank you in advance.
Correct, periodically checking, or your backend "voting" is not ideal for many reasons Including battery usage, high bandwidth usage and high backend resource usage.
"Sending data to mobile apps" is named "push notification".
The platform on Android comes with the built-in support for Google Cloud Messaging (GCM), which manages all low-level communications for you. To set up GCM "API Token" to register your app with Google, the app receives a "device ID" from the phone and shakes hands in your web server or the other backend. When your backend wants to send a push, it contacts Google and passes the device ID with a message. Google sends messages to the phone, where your app can listen for it and take some action.
For the official story, see. You can find instances of modifying your app, so that he can push for the push, as well as how to write his web server so that he can push the app.
GCM is extremely fast, so this is a good option, even if performance is a priority for you. After the request has been sent from the backend, the momentum is received in my experience immediately after the push. I note that on many factors GCM is not guaranteed
Oh, and it's free. This is considered as a good feature, not the main component,
Comments
Post a Comment