如何完成每一项活动在堆栈中除第一个在Android中 [英] How to finish every activity on the stack except the first in Android

查看:138
本文介绍了如何完成每一项活动在堆栈中除第一个在Android中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我移植一个iPhone应用程序到Android,我似乎无法找到弹出每个活动堆栈除了根活动的一种手段。

I'm porting an iPhone app to Android and I can't seem to find a means to pop each activity on the stack except the root activity.

在Objective-C中我会做类似下面的

In objective-c I would do something like the below

[navController popToRootViewControllerAnimated:YES];

任何人都知道我是否能有效地调用每个活动结束()的一些动作之后?

Anyone know if I can effectively call "finish()" on each activity after some action?

推荐答案

如果你想开始一个活动,比方说,您的主屏幕,并删除你的应用程序的堆栈所有其他活动,你可以使用:

If you want to start one Activity, say, your homescreen, and remove every other Activity in your application's stack, you can use:

Intent intent = new Intent(this, MainActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); // Removes other Activities from stack
startActivity(intent);

如果您也想提供该事件的MainActivity(如标志点击标题栏),您可以添加 FLAG_ACTIVITY_SINGLE_TOP 标志以及确保它不添加自己的另一个实例堆栈。

If you also want to provide this event in the MainActivity (such as a logo click in the title bar), you can add the FLAG_ACTIVITY_SINGLE_TOP flag as well to make sure it does not add another instance of itself to the stack.

这篇关于如何完成每一项活动在堆栈中除第一个在Android中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆