Android 在特定 activity 之上启动 activity

Android launch activity on top of particular activity

说,我有下面Activity

Activity A, Activity B, Activity C and Activity D

当前堆栈有以下条目

Activity C
Activity B
Activity A

我必须启动 Activity D 以便堆栈如下所示,

Activity D
Activity A

我必须设置什么标志?

你试过了吗?

<activity name="Activity D"
   android:allowTaskReparenting="true"
   android:taskAffinity="Activity A" >

考虑使用 A 作为调度程序。当您想从 C 启动 D 并在此过程中完成 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));
    }
}