如何控制机器人的活动栈/清除活性堆栈 [英] How to control activity stack/clear activity stack in Android
问题描述
我有去如下的应用程序(主页是发射活动):
I have an application that goes as follows (Home being the launch activity):
D
C
B
A
Home
我的流转如下:
My flow goes as follows:
用户启动的活动 A
从首页
,流向 B
和 C
。当用户离开活动 C
,我想 A
, B
和 C
被破坏。也就是说,如果用户presses 返回
的活动 D
,它可以追溯到首页
。
The user starts activity A
from Home
, which flows to B
and C
. When the user leaves activity C
, I want A
, B
, and C
to be destroyed. That is, if the user presses BACK
in activity D
, it goes back to Home
.
用户必须能够控制程序正常流过活动 A
, B
和<$ C $ ç> C 。所以,如果他们preSS的活动 C
返回按钮,它可以追溯到活动 B
。
The user must be able to control program flow normally through activityA
, B
, and C
. So if they press the back button in activityC
, it goes back to activity B
.
我已经看了意向标志,如 CLEAR_TOP
和 NEW_TASK
,但他们都不做我希望他们。
I've looked at Intent flags such as CLEAR_TOP
and NEW_TASK
, but none of them seem to do what I want them to.
我想AP preciate任何帮助!
I'd appreciate any help!
推荐答案
也许你正在寻找的 FLAG_ACTIVITY_TASK_ON_HOME
?它需要API级别11,但:(
Perhaps you are looking for FLAG_ACTIVITY_TASK_ON_HOME
? It requires API level 11 though :(
有关API级&LT; 11,这是可以做到:
for API level <11, this can be done:
开始活动B和C时,使用startActivityForResult()。当开始活动研发,做到这一点:
when starting activity B and C, use startActivityForResult(). When starting activity D, do this:
startActivity(D);
setResult(KILL_YOURSELF); //KILL_YOURSELF is some arbitrary int that you use to identify that the other activities should exit
finish(); //finish the activity
这会杀了活动℃,然后在活动A和B,覆盖onActivityResult是这样的:
This will kill activity C. Then in activity A and B, override onActivityResult like this:
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if(resultCode == KILL_YOURSELF) {
setResult(KILL_YOURSELF);
finish();
}
}
因此b活动将结束,这反过来会触发onActivityResult在A,所以它也将完成。
Thus activity B will finish, which in turn will trigger onActivityResult in A, so it will also finish.
这篇关于如何控制机器人的活动栈/清除活性堆栈的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!