防止多次打开活动 [英] Prevent opening Activity for multiple times

查看:61
本文介绍了防止多次打开活动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用上有一个带有图标的通用菜单.单击一个图标将启动一个活动.有没有办法知道某个活动是否已经在运行,并阻止它多次启动(或从多个条目启动)?还可以将处于onPause状态的活动置于最前面吗?

I have a common menu on my app with icons. Clicking an icon will start an Activity. Is there a way to know if an activity is already running and prevent it from starting multiple times (or from multiple entries)? Also can I bring an activity that is in onPause state to the front?

推荐答案

使用此:

intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);

在启动Activity时.

来自文档:

如果在传递给Context.startActivity()的Intent中进行设置,则此标志将 使启动的活动被带到任务的最前面 历史记录堆栈(如果已在运行).

If set in an Intent passed to Context.startActivity(), this flag will cause the launched activity to be brought to the front of its task's history stack if it is already running.

这篇关于防止多次打开活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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