hqtay
hqtay

Reputation: 430

When does it make sense to use android GCM?

When would it be useful to use android GCM?

As far as I can understand it's a push rather than pull mechanism.

Currently am using the usual http client to send a post and get json response data back from my server. Not sure if it makes sense to use GCM as have seen ppl using it to update sqlite db on android etc.

Upvotes: 1

Views: 264

Answers (2)

CommonsWare
CommonsWare

Reputation: 1006564

As far as I can understand it's a push rather than pull mechanism.

The latest update supports both push and pull, though it is mostly thought of as push (server -> device, by way of Google's servers).

Currently am using the usual http client to send a post and get json response data back from my server.

That works fine, when the device knows to initiate that work.

GCM push events are designed around situations where the server knows something needs to happen, but a device does not.

For example, take Remember the Milk (RTM). This is a "Web 2.0" to-do list service. You can access it from a Web browser and from mobile apps. When you make a change in your Web browser, if you also have the Android app installed and tied to the same RTM account, the RTM servers will use GCM to tell the device that there has been a change to the to-do entries. RTM could conceivably push down the entire bit of info in the 4K GCM payload, or it could simply be a trigger to cause the RTM Android app to use normal Web service calls to pull down the data.

This is more efficient than a polling architecture (e.g., RTM checks every five minutes for updates), as we only do significant network I/O when there is real work to do. It is also (usually) faster, in that GCM messages are (usually) delivered in real(-ish) time, and so the Android app can be in sync more quickly than it likely would with a polling architecture.

Upvotes: 2

Michael Banzon
Michael Banzon

Reputation: 4967

In the case you describe your code/app initiates the request when it require a response from the server. This is the correct way in such situations.

Push messaging (in the case of Android: GCM) is the correct approach if the server have events occuring that require some sort of initialization of communications. For direct messaging or e-mail systems where the server acts online at all times on the user/clients behalf - it can send a push message to initiate required communication (deliver message or initiate e-mail fetch).

Upvotes: 1

Related Questions