I am using push notifications in Android. When I receive a push notification, I want to open the application if it is still running, else it should open a new instance of it.
I am using
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent,
Intent.FLAG_ACTIVITY_CLEAR_TOP |
Intent.FLAG_ACTIVITY_SINGLE_TOP |
Intent.FLAG_ACTIVITY_NEW_TASK);
But when I receive a push notification now and I click on it, nothing happens.
How can I still achieve this by using flagIntents?
Push notifications do not require any additional app to be functional — the recipient can see the notification even if the app is not running. Almost every app offers an option for push notifications where the user can opt-out or opt-in to receive those notifications.
Android PendingIntent In other words, PendingIntent lets us pass a future Intent to another application and allow that application to execute that Intent as if it had the same permissions as our application, whether or not our application is still around when the Intent is eventually invoked.
You need to set the Intent flags on the Intent
. You were specifying them in the call to get a PendingIntent
. Try this:
notificationIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP |
Intent.FLAG_ACTIVITY_SINGLE_TOP |
Intent.FLAG_ACTIVITY_NEW_TASK);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
notificationIntent, 0);
set following things in your Android Mainfest file
android:noHistory="true"
android:launchMode = "singleTop"
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