特定活动之上的Android启动活动

时间:2015-12-16 14:14:51

标签: android android-activity back-stack

说,我有以下活动

Activity A, Activity B, Activity C and Activity D

目前堆叠位于条目

之下
Activity C
Activity B
Activity A

我必须启动Activity D,以便堆栈变得如下,

Activity D
Activity A

我必须设置什么标志?

2 个答案:

答案 0 :(得分:3)

考虑使用A作为调度程序。如果您想从D启动C并在此过程中完成CB,请在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" >
相关问题