Mikelbstek Mikelbstek - 5 months ago 52
Android Question

Disabling GCM push notification

I use GCM push notification for my Android app which is basically an instant messenger like Line/What's App. In my app, even after the user logs out, the push notification continue to happen. IN other words, I have no control over the notifications.

Ideally, I would like the notifications to stop when the user logs out of the app and resume after he logs in. Thanks in advance.


You should use SharedPreferences.

You should have a preference that contain the value if the user should be alerted or not. Let's say, once a user logged out - set the preference value to false. Now,in your GCMIntentService in the onMessage method, check the value of the preference, if its false, just do nothing.

Have a look at this example:

How to use SharedPreferences in Android to store, fetch and edit values