- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
在android中我有以下路径:
Activity 1 -> Activity 2 -> Activity 3 -> ... Activity N -> 按下按钮 ...
当按下按钮时,我想清除/完成从 Activity 2 到 N 的所有 Activity ,然后转到 Activity X。换句话说,我想完成所有 Activity ,直到最初的一个,然后移动到另一个。
如果我使用标志:
CLEAR_TOP、CLEAR_TASK、NEW_TASK 等
从理论上讲,它会用第一个 Activity 完成所有以前的 Activity 。有没有办法让第一个 Activity 保持活跃并转移到 Activity X?
最佳答案
我不确定我是否理解这个问题。或者更确切地说,无法使用 FLAG_ACTIVITY_CLEAR_TOP
的原因。
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.
如果我没理解错的话,这正是你想要的。特别是对于,
Activity 1 -> Activity 2 -> Activity 3 -> ... Activity N -> press button ...
使用 Activity2.class
和 标志启动 Intent FLAG_ACTIVITY_CLEAR_TOP | FLAG_ACTIVITY_SINGLE_TOP
将返回到 Activity2 的现有实例(而不是创建一个新实例)并在 onNewIntent()
中传递新 Intent 。您只需要为此 Intent 添加一个额外的内容,这样该方法就会知道它应该在之后调用 ActivityX。
也就是说,除非我遗漏了什么。 :)
关于Android清除/完成以前的 Activity ,除了一个,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24026051/
我是 firebase 的新手,我正在尝试分页查询。我喜欢有一个“下一个”和“上一个”按钮。我的下一个按钮工作正常,我的问题是单击上一个 引用:https://firebase.google.com/
抱歉,标题这么蹩脚,但我只是不知道该放什么,希望你能理解。另外,我不知道以前是否有人问过类似的问题,因为我不知道合适的关键字 - 因此也无法用谷歌搜索。 基本上...在查看preg_match_all
我想在 TFS 中 check out 一个检入文件的先前版本。我可以轻松获得特定文件的变更集 ID 列表,但无法弄清楚如何 checkout 以前的版本。 我目前的代码: var workspace
我想使用 @FunctionalInterface来 self 代码中的 Java 8,但我希望能够将生成的类文件与 Java 6 一起使用。我认为我应该将源版本设为 1.8 , 目标版本为 1.6
自从 versions 被删除以来,我一直无法找到安装以前版本软件的方法。命令并点击 Homebrew。我在 2008 Mac Pro (3,1) 上运行 macOS 10.14.3 (Mojave)
当我开始当前的项目时,App Store 中已经有一个应用程序。此应用程序仅适用于 iPhone。 我的第一个任务是测试和构建一个也可以在 iPod Touch 上运行的版本。 大约 3 周前,App
我在 GitHub 上有一个曾经是 fork 的 repo,但现在不是了,因为我已经删除了原始项目的任何痕迹并开始了一个同名的新项目。 但是,GitHub 仍然表示该项目是 fork 的。有什么方法可
我是一名优秀的程序员,十分优秀!