android - 防止多次打开Activity

标签 android android-activity

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

最佳答案

使用这个:

intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);

在启动Activity时。

来自 documentation :

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.

关于android - 防止多次打开Activity,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8906456/

相关文章:

android - 进一步理解 setRetainInstance(true)

android - 对于 Google API Access,我可以为同一个 Android 包名称创建多个客户端 ID 吗?

java - 当我将默认的 xml 布局文件更改为另一个时,Android 应用程序崩溃

Android - 视频重新启动或恢复

android - Activity 跳过 100 帧?花了太长时间才出现?

android - 如何使用 ViewPager 在 Activity 中显示存储在 SD 卡上的图像?

android - 服务- Activity 沟通

Android 我可以避免调用 onCreate() 吗?

android - 如何在从数据库中检索的编辑框中设置文本(通过使用 php 文件)

android - 如何连接到 Android 上的 IPv6 地址?