简体   繁体   English

如何清除活动堆栈并仅启动一项活动?

[英]How can I clear activity stack and start only one activity?

I launched next activity with these flags to clear the backstack.我用这些标志启动了下一个活动来清除 backstack。

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

and also tried with也试过

addFlags(Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK)

I've added this too.我也加了这个。

addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)

But all of the result are the same like this.但是所有的结果都是这样的。

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

As you can see, it cleared only the oldest one.如您所见,它只清除了最旧的一个。 How can I clear the backstack clearly?我怎样才能清楚地清除backstack?

What I expect is:我期望的是:

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

Actually, My code had nothing wrong.实际上,我的代码没有错。 But I set singleInstance to that activity, so it didn't work.但是我将singleInstance设置为该活动,因此它不起作用。

because singleInstance seems higher priority, so it won't be overwritten by singleTask(NEW_TASK+CLEAR_TASK or CLEAR_TOP)因为 singleInstance 似乎优先级更高,所以它不会被 singleTask(NEW_TASK+CLEAR_TASK or CLEAR_TOP) 覆盖

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM