gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 01:23:34 24 4
gpt4 key购买 nike

我有一个 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com