Android - Clear task flag not working for PendingIntent

android, android-intent, android-notifications, android-pendingintent

Solution

if u r using solution 1 then Just remove the `launchMode="singleTask"` from manifest

1)

 final Intent notificationIntent = new Intent(mContext, ActivityA.class);

 notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);

 PendingIntent contentIntent = PendingIntent.getActivity(myContext, 0, notificationIntent, 0);

OR

2)

       <activity 
       android:name=".ActivityA" 
       android:theme="@style/theme_noActionBar" 
       android:noHistory="true">

OR

3)

<activity android:name=".ActivityA" android:launchMode="singleTop">

Problem

I have a task stack of A > B > C. I am currently on C, and then I press the home button. I get a notification with the intent to take me to Activity A. I press the notification, and I'm at A but if I press back, I go to C, then B, then A. I am setting up my PendingIntent like so. Anything clearly wrong with it? ``` final Intent notificationIntent = new Intent(mContext, ActivityA.class); notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK); PendingIntent contentIntent = PendingIntent.getActivity(myContext, 0, notificationIntent, 0); ``` EDIT 1: I tried the suggestion here: Clear all activities in a task? ``` notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK); ``` but I still get the same result. My activity A starts in my application task stack, I press back and go to C, then B, then A again. I am starting to think that this is either not possible in Android or it's not possible when using a pending intent. EDIT 2: This is not a matter of what flags are needed. More of an issue of what could be going wrong that the flags seem to have no effect.

Original source

Related problems