Android的 - 清除任务标志不工作的PendingIntent标志、任务、工作、Android

2023-09-07 10:16:35 作者:多的是你不知道的事@

我有A> B> C的任务堆栈我目前的C,然后我preSS home键。我收到了通知,意图要带我到活动答:我preSS的通知,和我在一个,但如果我preSS回来,我去到C,那么B,则A

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.

我建立我的PendingIntent像这样。任何显然是错误的呢?

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);

修改1:

我想建议在这里:清除任务中的所有活动

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

但我仍然得到同样的结果。我的活动A开始在我的应用任务堆栈,我preSS回转到C,然后是B,那么A了。

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.

我开始认为这不是没有可能的Andr​​oid或它使用挂起的意图时,是不可能的。

I am starting to think that this is either not possible in Android or it's not possible when using a pending intent.

编辑2: 这不是需要什么样的标志的问题。更多的东西可以去错了一个问题,该旗似乎没有任何效果。

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.

推荐答案

如果乌拉圭回合使用的解决方案1,那么只需删除 launchMode =singleTask从清单

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);

2)

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

3)

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