[英]Destroy middle activity in android
I just saw a piece of code: 我刚刚看到了一段代码:
public class MyApplication extends Application {
private List<Activity> activityList = new LinkedList<Activity>();
private static MyApplication instance;
private MyApplication() {
}
public static MyApplication getInstance() {
if (null == instance) {
instance = new MyApplication();
}
return instance;
}
public void addActivity(Activity activity) {
activityList.add(activity);
}
public void exit() {
for (Activity activity : activityList) {
activity.finish();
}
System.exit(0);
}
}
I never thought that we can take control of other activity beside the current one. 我从未想到我们可以控制当前活动以外的其他活动。 I usually call finish() inside its own activity, now I saw this code, I realize that we can finish() other activity as well. 我通常在其自己的活动中调用finish(),现在我看到了这段代码,我意识到我们也可以完成其他活动。
Android stack is back stack architecture, so if I destroy any activity in the middle, what will happen? Android堆栈是后堆栈架构,因此,如果我在中间破坏了任何活动,会发生什么? For example, I have 5 activity in the back stack, let say I finish() the third one, will the second and fourth be linked together now? 例如,我在后堆栈中有5个活动,比如说我finish()第三个活动,现在第二个和第四个活动会链接在一起吗?
Android maintains a stack of the Activities being started, so the application which was started first goes to the bottom of the stack, the second one above it and henceforth. Android会维护一堆正在启动的“活动”,因此,首先启动的应用程序将进入堆栈的底部,第二个应用程序将位于堆栈的上方,此后一直。
So, if you remove the third Activity, the fourth one would come on top of the second Activity and thus they would get linked , as you have rightly understood from the code. 因此,如果您删除了第三个活动,则第四个活动将位于第二个活动的顶部,因此它们将被链接 ,正如您从代码中正确理解的那样。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.