gpt4 book ai didi

android - 如果后台堆栈中已经存在,则恢复 Activity 而不是启动

转载 作者:IT老高 更新时间:2023-10-28 21:54:42 26 4
gpt4 key购买 nike

我有一个 Activity_1 经过很多步骤,说

Activity_2 > Activity_3 .... 在一些 Activity_n 我更改了一些与 相关的数据Activity_1 并使用

调用它
Intent intent = new Intent(Activity_n.this, Activity_1.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);

刷新内容。但后来我可以一直回到我开始的Activity_1,那里有旧数据。

相反,我希望使用上述代码调用初始 Activity_1onResume()。或适当的标记

FLAG_ACTIVITY_CLEAR_TOP

consider a task consisting of the activities: A, B, C, D. If D calls startActivity() with an Intent that resolves to the component of activity B, then C and D will be finished and B receive the given Intent, resulting in the stack now being: A, B.

这是文档所说的,但不是我得到的。

最佳答案

你可以加这两行试试

intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

在你的 list 文件中写入 Activity

<activity
android:name=".SettingsActivity"
android:launchMode="singleInstance"
android:screenOrientation="portrait" >
</activity>

“singleTask”和“singleInstance” Activity 只能开始一个任务。它们始终位于 Activity 堆栈的根部。此外,该设备一次只能保存一个 Activity 实例——只有一个这样的任务。

您可以使用 SingleTask 或 SingleInstance

"singleTask"- 系统在新任务的根目录创建 Activity 并将 Intent 路由到它。但是,如果 Activity 的实例已经存在,系统会通过调用其 onNewIntent() 方法将 Intent 路由到现有实例,而不是创建一个新实例。

"singleInstance"- 与"singleTask"相同,只是系统不会在持有该实例的任务中启动任何其他 Activity 。 Activity 始终是其任务中唯一且唯一的成员。

引用此链接http://developer.android.com/guide/topics/manifest/activity-element.html

关于android - 如果后台堆栈中已经存在,则恢复 Activity 而不是启动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15359124/

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