PureSpider
PureSpider

Reputation: 407

Google Cloud Messaging: BroadcastReceiver or Service?

What is the generally preferred method of using GCM in its current state?

The documentation only talks about using it with a BroadcastReceiver and only mentions Services in one sentence without further explanation.

In my application, I need to be able to react to an unknown number of successive GCM messages and queue them so I can process them one by one. This processing needs to be done in order the messages are received in.

This cannot be done with a BroadcastReceiver, as for every broadcast received, a new instance of my receiver class is created (this was the method I tried first as per the getting started guide). Can it be done with a service or, more precisely, is the instance of my service kept between messages received?

If so, when and how does this service need to be started, added to the manifest, etc.?

I do not need to interact with my main application/UI. The service can do its business on its own.

Upvotes: 1

Views: 97

Answers (1)

Marcin Orlowski
Marcin Orlowski

Reputation: 75645

GCM message comes as broadcast so you must use BroadcastReceiver. If you need to queue them for any reason. just make your BroadcastReceiver hand the message to IntentService or anything else you find suitable for your task.

Upvotes: 2

Related Questions