【问题标题】:Android - restore activity stack after process killed?Android - 进程终止后恢复活动堆栈?
【发布时间】:2015-10-24 08:10:36
【问题描述】:

我在网上研究发现如果我的app进程被系统杀死了,下次用户回到它时,系统会恢复activity stack。也就是说,根活动之上的任何活动都保留在那里,但只有最上面的活动被重新创建。 (见here

我通过在监视器 (ddms) 中终止我的进程来测试这一点。我没有看到活动堆栈恢复。仅显示根活动。那么我在这里缺少什么吗?我还需要实现什么才能恢复堆栈?

我找到了“persistableMode”属性。那是我需要的吗? docs

还是 android:alwaysRetainTaskState? docs

【问题讨论】:

  • 请将相关链接(来自您的研究)添加到问题中。
  • 值得注意的是,如果应用被最近的滑动杀死,则活动堆栈不会恢复。在这种情况下,它会从启动器活动重新启动。
  • 你对这个问题有更深入的了解吗?我有同样的问题,但找不到合理的解释。
  • 我正在使用 Appcelerator Titanium。我认为这是阻止活动堆栈恢复的 Titanium 机制。我不确定。

标签: android android-activity


【解决方案1】:

主要取决于用于启动意图的标志

例如

Intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

 /** 
 * If set, this activity will become the start of a new task on this
 * history stack.
 *
 * This flag is generally used by activities that want
 * to present a "launcher" style behavior: they give the user a list of
 * separate things that can be done, which otherwise run completely
 * independently of the activity launching them.
 */

有关更多信息,请参阅 API 文档:

Tasks and Back Stack

另见:

【讨论】:

    猜你喜欢
    • 2011-07-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-11-16
    • 1970-01-01
    • 2021-12-28
    • 2013-08-08
    • 2011-07-15
    相关资源
    最近更新 更多