说,我有以下活动
Activity A, Activity B, Activity C and Activity D
目前堆叠位于条目
之下Activity C
Activity B
Activity A
我必须启动Activity D
,以便堆栈变得如下,
Activity D
Activity A
我必须设置什么标志?
答案 0 :(得分:3)
考虑使用A
作为调度程序。如果您想从D
启动C
并在此过程中完成C
和B
,请在C
中执行此操作:
// Launch A (our dispatcher)
Intent intent = new Intent(this, A.class);
// Setting CLEAR_TOP ensures that all other activities on top of A will be finished
// and setting SINGLE_TOP ensures that a new instance of A will not
// be created (the existing instance will be reused and onNewIntent() will be called)
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP|Intent.FLAG_ACTIVITY_SINGLE_TOP);
// Add an extra telling A that it should launch D
intent.putExtra("startD", true);
startActivity(intent);
A.onNewIntent()
中的执行此操作:
@Override
protected void onNewIntent(Intent intent) {
if (intent.hasExtra("startD")) {
// Need to start D from here
startActivity(new Intent(this, D.class));
}
}
答案 1 :(得分:1)
你试过这个吗?
<activity name="Activity D"
android:allowTaskReparenting="true"
android:taskAffinity="Activity A" >