Android back stack - 返回到back stack中的某个activity

标签 android android-intent back-stack

我有 Activity A -> B -> C -> D。如何从 Activity D 中打开现有的 B,清除 C 和 D?我最终会得到 A -> B。我不想重新创建一个新的 B。

最佳答案

我认为你必须使用FLAG_ACTIVITY_CLEAR_TOPFLAG_ACTIVITY_SINGLE_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.

The currently running instance of activity B in the above example will either receive the new intent you are starting here in its onNewIntent() method, or be itself finished and restarted with the new intent. If it has declared its launch mode to be "multiple" (the default) and you have not set FLAG_ACTIVITY_SINGLE_TOP in the same intent, then it will be finished and re-created; for all other launch modes or if FLAG_ACTIVITY_SINGLE_TOP is set then this Intent will be delivered to the current instance's onNewIntent().

关于Android back stack - 返回到back stack中的某个activity,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26394804/

相关文章:

android - 每个 Intent 都会在 Android 应用程序中启动一个新任务 - 如何防止?

ios - 在转换时清除返回堆栈

android - 如何使用自定义适配器动态更新 ListView?

android - 从 onContextItemSelected 显示的 DialogFragment 在暂停/恢复时不存在

android - 如何在Android中没有Intent且没有任何 View 窗口的情况下拍照

Android App Widget - 更改 TextView 内容的按钮

android - 启动另一个应用程序的 Activity

android - 调用 finish() 不会清除对 Activity 的内存引用

java - 接口(interface)声明为NULL

java - 从 fragment 的参数获取数据