Riju Baral
Riju Baral

Reputation: 11

Service in Android GCM push notification App

I am trying to create an android app which can receive push notifications. I have already got my device registered and obtained the GCM id.

However I am confused if I need to implement a service to listen to the push notifications ? I am aware that I need to implement a broadcast receiver to process the push notification. However I am not sure if service is required in my application.

My aim is to create an application which I can start/stop remotely. I intent to do it via push notifications.

Upvotes: 1

Views: 343

Answers (2)

Arthur Thompson
Arthur Thompson

Reputation: 9225

No, if you are using GcmListenerService like demonstrated here, the listening for incoming messages is handled for you.

So you do need a service, GcmListenerService is that service, but you don't need to write it yourself, just extend it and override onMessageReceived. You must still add the required declarations in your manifest though, and like Riju mentioned you should also extend InstanceIDListenerService to handle refreshed tokens, which is also demonstrated in the sample I liked to.

Upvotes: 1

NaCI
NaCI

Reputation: 41

No, you don't need to implement a service. Only a broadcast receiver is enough to get messages. You can start application after receive a message via GCM.

Upvotes: 0

Related Questions