gpt4 book ai didi

android - 从 Activity 堆栈中删除 Activity 并启动所请求 Activity 的新实例

转载 作者:行者123 更新时间:2023-11-29 17:53:16 26 4
gpt4 key购买 nike

在我的 android 应用程序中,我有以下简单的场景:

Activity A 调用 Activity B,所以 Activity Stack 是(从上到下):

B - A

现在我想从 B 调用 A,完成 B Activity 。

如果我简单地使用 finish() Activity B 将完成,但 A 仍保持之前的状态。相反,我希望 A 处于初始状态。所以我想完成 Activity A 的前一个实例并创建它的新实例(从堆栈中删除 B)

我如何执行此任务?

最佳答案

使用标志 intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP) 在 B 中调用 startActvitity A。

If set, and the activity being launched is already running in the current task, then instead of launching a new instance of that activity, all of the other activities on top of it will be closed and this Intent will be delivered to the (now on top) old activity as a new Intent.

For example, 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.

关于android - 从 Activity 堆栈中删除 Activity 并启动所请求 Activity 的新实例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21425396/

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