java - 如何重用一个 Intent 并将其带到最前面?

标签 java android android-intent

我有一个 HashMap 来跟踪我的运行 Intent ;每次我启动一个运行自定义 ChatActivity 类的新 Intent 时,我都会将其保存到 HashMap。

Intent 保持活跃(我没有对它们使用 finish());我希望能够将其中一个“返回”,以便在该 Intent 被激活时我更改的每个 View 和信息仍然存在。

我曾尝试使用如下各种形式的标志,但没有成功。

Intent intent = data.getDictionary().get(getName(position));
intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
startActivity(intent);

似乎当我使用标志时什么也没有发生,当我不使用它时,它只是从新鲜开始一个新的 Activity (不是我想要的行为)。

我怀疑我的问题是因为我所有的 Intent 都运行在同一个类上,但我会让你来判断。

谢谢。

最佳答案

您可能想在您的 list 文件中尝试这个:android:launchMode="singleTop"

根据文档:

If, when starting the activity, there is already an instance of the same activity class in the foreground that is interacting with the user, then re-use that instance. This existing instance will receive a call to Activity.onNewIntent() with the new Intent that is being started.

关于java - 如何重用一个 Intent 并将其带到最前面?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36749623/

相关文章:

android - 是否可以在 Android 上使用 OpenCV 进行缩放和聚焦?

android - 打开小部件选择器时系统设置强制关闭

java - Android中的 Intent 服务错误

java - 当我尝试读取通过 Intent 传递的 Vector 时出现 NullPointerException

java - 如何复制正在运行的应用程序的 RAM,保存它,然后将其重新加载到 RAM 中?

java - 如何对openCV中的图片应用高斯模糊?

java - TreeMap 在不知道字符串的情况下查找字符串类别的值?

java - N-Queens 不打印所有解决方案

android - 如何在我的 Android 应用程序中使用 django 身份验证(django.contrib.auth)

Android 和 Twitter4j : Handling OAuth with a Webview widget?