[英]Clearing stack including activities in different tasks
I have a main activity A. There are two scenarios 我有一个主要活动A.有两种情况
1) A launches B. B has launchmode singleTask and is launched with FLAG_ACTIVITY_NEW_TASK. 1)启动B. B启动模式singleTask并使用FLAG_ACTIVITY_NEW_TASK启动。 now I have a menu option in B which performs a delete operation and starts the activity A.
现在我在B中有一个菜单选项,它执行删除操作并启动活动A.
2) A launches B, which launces C it also contains the menu option to perform delet opereation. 2)A启动B,它启动C它还包含执行delet opereation的菜单选项。
I want A to be started with clearing the stack in both the scenarios but the activities belonging to another task still present there I am stuck is there a way to clear the stack. 我希望A开始在两个场景中清除堆栈,但属于另一个任务的活动仍然存在于那里我被卡住有一种方法来清除堆栈。
try using following code on delete opereation on both B and C activity 尝试在B和C活动上使用以下代码删除操作
Intent intent=new Intent(B.this, A.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
If i talk about your second scenario then FLAG_ACTIVITY_TOP_CLEAR
will clear the stack.. 如果我谈论你的第二个场景,那么
FLAG_ACTIVITY_TOP_CLEAR
将清除堆栈..
And your stack now will be only A
instead of ABCA
. 而你的筹码现在只有
A
而不是ABCA
。
and in second case AFAIU your problem you have only two activity A and B so if you want to restart A then after restarting A manually finish B. 在第二种情况下AFAIU你的问题你只有两个活动A和B所以如果你想重启A然后重启后A手动完成B.
Hope you got some trick. 希望你有一些技巧。
Another thing if you have activity with launchmode=SingleTask
then you can use flag_activity_brought_to_front. 另外一件事,如果你有
launchmode=SingleTask
活动,那么你可以使用flag_activity_brought_to_front。
That will act like
ABc to A ABc到A.
为什么不在再次呼叫A之前完成B和C?
finish();
My method can not meet your goal A to be started with clearing the stack
,But when user choose delet opereation
and start B from A again the task that include A and B will be reset. 我的方法无法满足你的目标
A to be started with clearing the stack
,但当用户选择delet opereation
并再次从A启动B时,包含A和B的任务将被重置。
Use the flag FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET
to mark the task will be clear when needed when you first start activity B from A, then if user choose delet opereation
menu item from B or C, you set a flag, so next time from A(A should be single_task launch mode in manifest), you use the flag FLAG_ACTIVITY_RESET_TASK_IF_NEEDED
to start B. This flag will clear B and all top of the B. 当你第一次从A开始活动B时,使用标志
FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET
标记任务将在需要时清除,然后如果用户从B或C中选择delet opereation
菜单项,你设置一个标志,所以下次从A(A应该是single_task)在manifest中启动模式),你使用标志FLAG_ACTIVITY_RESET_TASK_IF_NEEDED
来启动B.这个标志将清除B和B的所有顶部。
Hope this will help you :) 希望这个能对您有所帮助 :)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.