0

我使用这些标志启动了下一个活动以清除后台堆栈。

addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK)

并尝试过

addFlags(Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK)

这个我也加了。

addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)

但是所有的结果都是这样的。

D/activity-stack: idx: 0
     num: 1, base-name: com.example.ui.result.ResultActivity, top-name: com.example.ui.result.ResultActivity
D/activity-stack: idx: 1
     num: 1, base-name: com.google.android.apps.nexuslauncher.NexusLauncherActivity, top-name: com.google.android.apps.nexuslauncher.NexusLauncherActivity
D/activity-stack: idx: 0
     num: 1, base-name: com.example.ui.result.OrderActivity, top-name: com.example.ui.result.OrderActivity
D/activity-stack: idx: 1
     num: 1, base-name: com.example.ui.result.ResultActivity, top-name: com.example.ui.result.ResultActivity
D/activity-stack: idx: 2
     num: 1, base-name: com.google.android.apps.nexuslauncher.NexusLauncherActivity, top-name: com.google.android.apps.nexuslauncher.NexusLauncherActivity
D/activity-stack: idx: 0
     num: 1, base-name: com.example.ui.result.PaymentActivity, top-name: com.example.ui.result.PaymentActivity
D/activity-stack: idx: 1
     num: 1, base-name: com.example.ui.result.OrderActivity, top-name: com.example.ui.result.OrderActivity
D/activity-stack: idx: 2
     num: 1, base-name: com.example.ui.result.ResultActivity, top-name: com.example.ui.result.ResultActivity
D/activity-stack: idx: 3
     num: 1, base-name: com.google.android.apps.nexuslauncher.NexusLauncherActivity, top-name: com.google.android.apps.nexuslauncher.NexusLauncherActivity
D/activity-stack: idx: 0
     num: 1, base-name: com.example.ui.result.CompleteActivity, top-name: com.example.ui.result.CompleteActivity
D/activity-stack: idx: 1
     num: 1, base-name: com.example.ui.result.OrderActivity, top-name: com.example.ui.result.OrderActivity
D/activity-stack: idx: 2
     num: 1, base-name: com.google.android.apps.nexuslauncher.NexusLauncherActivity, top-name: com.google.android.apps.nexuslauncher.NexusLauncherActivity

如您所见,它只清除了最旧的一个。我怎样才能清楚地清除backstack?

我期望的是:

D/activity-stack: idx: 0
     num: 1, base-name: com.example.ui.result.Completectivity, top-name: com.example.ui.result.CompleteActivity
D/activity-stack: idx: 1
     num: 1, base-name: com.google.android.apps.nexuslauncher.NexusLauncherActivity, top-name: com.google.android.apps.nexuslauncher.NexusLauncherActivity
4

1 回答 1

0

实际上,我的代码没有任何问题。但是我设置singleInstance了那个活动,所以它没有用。

因为 singleInstance 似乎优先级更高,所以它不会被 singleTask(NEW_TASK+CLEAR_TASK or CLEAR_TOP) 覆盖

于 2021-07-06T04:58:57.483 回答