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
Call This Method GCMRegistrar.unregister(context); when the user signs out to stop receiving the push messages.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With