Reputation: 228
I am working on a chat project. When a push notification is being received from GCM, i need to navigate to the chat contact list and clear the previously opened activity of my application.
Upvotes: 3
Views: 2699
Reputation: 1114
Adding "taskAffinity" and "excludeFromRecents" in the activity tag in the manifest along with the flag "FLAG_ACTIVITY_NEW_TASK" in intent as saranya suggested did the trick for me.
<activity
android:name=".MainActivity"
android:launchMode="singleTask"
android:taskAffinity=""
android:excludeFromRecents="true">
val notificationIntent = Intent(this,
MainActivity::class.java).setFlags(Intent.FLAG_ACTIVITY_NEW_TASK or
Intent.FLAG_ACTIVITY_CLEAR_TASK)
val pendingIntent: PendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0)
Upvotes: 0
Reputation: 228
While passing the pending intent in GCMIntent Service, it is necessary to set flag for intent. The code is below. Please make use of it if anyone struggling with this concept.
PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
new Intent(this, MainActivity.class).setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
Intent.FLAG_ACTIVITY_CLEAR_TASK), 0);
Upvotes: 7
Reputation: 4701
I would suggest you to read documentation about Notification Navigation and Notification Update
Upvotes: 2