Android 12 notification/widget PendingIntents show other activity after closing

Viewed 149

After updating my device to android 12, activities that I start from notifications or widgets using a PendingIntent will show another activity that was started before (like the launcher activity) after closing that activity.

I've tried using FLAG_ACTIVITY_NEW_TASK, FLAG_ACTIVITY_CLEAR_TASK or FLAG_ACTIVITY_SINGLE_TOP but that doesn't seem to work.

2 Answers

You need to set the activity launch mode.

 android:launchMode=["standard" | "singleTop" |
                          "singleTask" | "singleInstance" | "singleInstancePerTask"]

In your case, you will need to set it to single instance to prevent that problem.

android:launchMode="singleInstance"

You can check more about setting up activites here -> element

Using android:launchMode="singleInstance" on the activity in AndroidManifest.xml seems to solve the issue

Related