我如何崩溃"儿童活动"? [英] How do I collapse "child activities"?
问题描述
例子:我有一个具有以下行为3活动Android应用程式:
Example: I have an android app with 3 activities that has the following behaviors:
A (Home) -> B -> C
Activity A launches Activity B
Activity B launches Activity C
When user is on Activity B and they hit the Back button, it takes them Activity A
When user is on Activity C and they hit the Back button, it takes them Activity B
我想,当用户在活动C,如果他们打出了我的根活动按钮,它会带他们到活动A无添加活动A的新实例向后退堆栈中。
What I would like is when user is on Activity C, if they hit the "My Root Activity" button, it will take them to Activity A without adding a new instance of Activity A to the back stack.
所以我不希望有:
1) A
2) A-B
3) A-B-C
4) A-B-C-A
我想的是:
1) A
2) A-B
3) A-B-C
4) A
我怎样才能做到这一点?
How can I do this?
推荐答案
我有每个孩子的活动扩展基地的活动。在基础活性,我所限定的的onActivityResult(),这将施加面漆()如果在堆栈设置特定的结果code的顶部的活性。所以,如果他们打的活动C中的我的根活动按钮,将递归地卷起到活动A.后退按钮保持它的功能。
I have each child activity extend a base activity. In the base activity, I defined an onActivityResult() which will impose a finish() if the activity at the top of the stack set a specific resultCode. So if they hit the "My Root Activity" button on Activity C, it will recursively roll up to Activity A. The Back button maintains it's functionality.
这是一种罕见的情况下,我会用singleTask,但在启动活动A涉及重新加载它,我不想情侣活动的C依赖。
This is a rare scenario as I would have used "singleTask" but launching Activity A involves reloading it's dependencies which I don't want to couple of Activity C.
这篇关于我如何崩溃"儿童活动"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!