Reputation: 13450
Not a duplicate of: Pending intent always make new activity since no solution is there.
Here is my PendingIntent:
Intent intent = new Intent(context, MainActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP);
return PendingIntent.getActivity(context, REQUEST_CODE_PUSH_MESSAGE_TYPE, intent, PendingIntent.FLAG_CANCEL_CURRENT);
If I close the app (e.g. back button) and use this PendingIntent in the notification it will create a new activity.
If however I pause the app (e.g. home button) and click on the same notification the activity (and the containing fragment) will be resumed.
How can I create a new activity (and its fragment) everytime I use this PendingIntent?
Upvotes: 1
Views: 1674
Reputation: 95578
Remove Intent.FLAG_ACTIVITY_SINGLE_TOP
from the Intent
. The use of Intent.FLAG_ACTIVITY_SINGLE_TOP
tells Android to reuse the existing instance of the Activity.
Upvotes: 0
Reputation: 157447
use the Intent.FLAG_ACTIVITY_NEW_TASK
From the documentation
If set, this activity will become the start of a new task on this history stack.
you can add in or
, with the other flags you are using
intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
Upvotes: 1