首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何调出Android的activity后台中的activity?

如何调出Android的activity后台中的activity?
EN

Stack Overflow用户
提问于 2019-11-26 15:35:28
回答 1查看 227关注 0票数 0

假设我有一个名为ActivityA的活动和另一个名为ActivityB的活动。在每个活动中,我都有一个按钮,当它被点击时,它会打开另一个活动。当按钮被点击时,我想做以下工作:

代码语言:javascript
复制
check if there is an existing type of the target Activity in the activity back-stack or not, if there is, bring that Activity to the top and if not create new Intent and then go to that Activity.
How can I implement this?

谢谢。

EN

回答 1

Stack Overflow用户

发布于 2019-11-28 01:08:20

很简单。

代码语言:javascript
复制
Intent intent = new Intent(this, TargetActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
startActivity(intent);

这就是你想要的。如果任务堆栈中已经存在TargetActivity的实例,则该实例将被重新排列并移到堆栈的顶部(前面)。如果没有现有的TargetActivity实例,安卓将创建一个新实例并将其放在堆栈的顶部。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/59045860

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档