如何清除栈目前的活动? [英] How to clear current activities in the stack?
问题描述
支持应用程序启动活动A,那么A启动活动B和完成自身。该活动结束后B开始活动℃。
Support App starts activity A, then A starts activity B and finishes itself. After that activity B starts activity C.
现在堆栈含有B和C,其中C在顶部。
Now the stack contains B and C, with C at the top.
然后我点击活动℃的按钮,并希望它清除B和C,并启动活性的,也就是我想活性的是在堆栈中的唯一活动。我如何能做到吗?
Then I click a button in activity C, and want it to clear B and C and start activity A, i.e. I want activity A to be the only activity in the stack. How can I make it?
谢谢!
编辑:我做了一个测试,使用FLAG_ACTIVITY_CLEAR_TOP。但是,这并不在我的情况下工作,因为活性的没有运行被点击活动C钮时。
I made a test to use FLAG_ACTIVITY_CLEAR_TOP. But it didn't work in my case, because activity A is not running when button in activity C is clicked.
推荐答案
设置的 FLAG_ACTIVITY_CLEAR_TOP 把你的意图开始活性的。
Set the FLAG_ACTIVITY_CLEAR_TOP flag on your intent to start activity A.
编辑:有没有你不能离开一个持续的一个原因?然后,你可以做的建议。
Is there a reason you can't leave A going? Then you could do as suggested.
否则,另一个(更复杂)选项:
Otherwise, another (more complicated) option:
在B启动ÇforResult。当A是从C开始,你可以用一个结果结束ç指示向B也退出。
In B start C forResult. When A is started from C, you could finish C with a result indicating to B to also exit.
这篇关于如何清除栈目前的活动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!