Your push notifications are received by service class in your app (and I guess you are interested in foreground activity from your app, i.e. the same code base).
Maybe there are more elegant and smarter solutions, but you can also do a bit crude one like this:
Add flag (static boolean doNotCreateNotification = false;
is enough for the simple scenario of chat activity prohibiting notifications) to MyApplication extends Application
class (add new one, if you don't have yet one in your project, make sure you reconfigure the project correctly to use custom Application
class).
Now this static flag will be pretty much "global" for all the code which is running from your app, including all activities and/or background service processing notifications.
The Activity
life cycle guarantees that onResume
is called when activity becomes foreground+active one, and onPause
when the activity is leaving such state. So you can update the global flag in these to true/false in the onResume/onPause
methods.
Then in the service processing received notification you can check if the flag is set to true
and just discard the notification data without creating badge in the OS.