假设我有3项活动A,B和C.A导致B导致C.我希望能够在A和B之间前后移动,但是我想完成A和B一旦C开始。我知道如何通过意图启动C时关闭B,但我如何在C启动时关闭A?从其他活动完成活动
2
A
回答
1
当您打开C活动时使用此标志。
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
这将清除C.
0
的顶部由于A
所有的活动是你的根(起点)的活性,可以考虑使用A
作为调度员。如果要启动C
并完成所有其他活动(下)之前,这样做:
// Launch ActivityA (our dispatcher)
Intent intent = new Intent(this, ActivityA.class);
// Setting CLEAR_TOP ensures that all other activities on top of ActivityA will be finished
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
// Add an extra telling ActivityA that it should launch ActivityC
intent.putExtra("startActivityC", true);
startActivity(intent);
在ActivityA.onCreate()
做到这一点:
super.onCreate();
Intent intent = getIntent();
if (intent.hasExtra("startActivityC")) {
// Need to start ActivityC from here
startActivity(new Intent(this, ActivityC.class));
// Finish this activity so C is the only one in the task
finish();
// Return so no further code gets executed in onCreate()
return;
}
这里的想法是,你推出ActivityA(您的调度员)使用FLAG_ACTIVITY_CLEAR_TOP
,以便它是该任务中的唯一活动,并告诉它您想要启动的活动。然后它将启动该活动并完成自己。这将使您只在Activity中留下ActivityC。
相关问题
- 1. Android:从其他活动完成活动
- 2. 如何完成其他活动的活动
- 3. 我想完成其他活动的活动
- 4. 如何通知活动已完成其他活动
- 5. 如何完成其他活动的活动
- 6. 从非活动完成活动
- 7. 如何在“活动B”之后完成“活动A”? (完成一个活动,因为其他)
- 8. 从事其他活动?
- 9. 安卓:从其他活动
- 10. 我想从其他活动
- 11. 如何从其他活动启动启动器活动?
- 12. 在移动到其他活动时完成碎片?
- 13. 开始活动,不完成活动
- 14. 活动组中的完成活动
- 15. 如何从其他活动启动Android AppWidget的配置活动?
- 16. Android活动无法从其他活动启动
- 17. 如果从其他活动开始活动,则启动方法
- 18. 如何完成除主要活动以外的所有活动并致电其他活动
- 19. 从一个活动传递图像的其他活动
- 20. 从具有线程的活动开始其他活动
- 21. 将图像从一项活动传递到其他活动
- 22. 如何从其他活动重新加载活动
- 23. 如何从其他活动更新活动的适配器?
- 24. 无法从MainActivity中的其他活动调用活动
- 25. Android:在活动中使用ButterKnife从其他活动延伸
- 26. 如何将图像从活动发送到其他活动?
- 27. Android - 从子活动onResume()开始一个完成的父活动()
- 28. 使用EventBus从基本活动完成活动?
- 29. Android - 从另一个活动完成活动
- 30. 正在完成其他课程的活动
对我来说听起来像A和B在** C下(即:在C之前),而不是在C之下。在这种情况下,FLAG_ACTIVITY_CLEAR_TOP将无济于事。 – 2013-03-21 20:51:47