假设我有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. 从其他活动完成活动
- 2. Android:从其他活动完成活动
- 3. 完成其他活动的活动
- 4. 如何完成其他活动的活动
- 5. 如何通知活动已完成其他活动
- 6. 如何在完成其他活动后才能调用活动?
- 7. Android:如何通知其他活动完成的活动()
- 8. 如何完成其他活动的活动
- 9. 我想完成其他活动的活动
- 10. 从其他活动恢复活动
- 11. 活动从背景或其他活动
- 12. 从其他活动中打开活动
- 13. 从非活动完成活动
- 14. 如何在“活动B”之后完成“活动A”? (完成一个活动,因为其他)
- 15. 如何完成在Android中启动其他活动时的活动?
- 16. 启动和活动完成后活动
- 17. 从事其他活动?
- 18. 安卓:从其他活动
- 19. 我想从其他活动
- 20. 安卓:从其他活动
- 21. 调用从其他活动
- 22. 从片段完成活动
- 23. 致电完成()从活动
- 24. 从其他活动启动主启动器活动
- 25. 如何从其他活动启动启动器活动?
- 26. 在其他活动上显示活动
- 27. 禁用其他活动的活动?
- 28. 在移动到其他活动时完成碎片?
- 29. 活动组中的完成活动
- 30. 开始活动,不完成活动
对我来说听起来像A和B在** C下(即:在C之前),而不是在C之下。在这种情况下,FLAG_ACTIVITY_CLEAR_TOP将无济于事。 – 2013-03-21 20:51:47