【问题标题】:Replacing fragments in SingleTask activities替换 SingleTask 活动中的片段
【发布时间】:2020-08-20 18:53:38
【问题描述】:

活动 A 是一个 SingleTask 活动。在其 OnCreate 回调中,我创建一个片段并将其附加到布局。

Activity B 现已启动,A 已暂停并调用其 OnSaveInstanceState。

现在以新的意图重新调用活动 A(由于 B 中的交互)。在 OnNewIntent() 中,我根据新意图创建一个新片段并替换之前的片段。

这会导致 IllegalStateException:在 onSaveInstanceState 之后无法执行此操作。

这样做的正确方法是什么?即使调用了 OnNewIntent(),框架似乎仍然认为 A 处于暂停状态。

【问题讨论】:

    标签: android android-fragments android-lifecycle


    【解决方案1】:

    您需要调用super.onNewIntent(intent) 来更新 FragmentManager 的状态,以便您可以执行 FragmentTransactions。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-04-11
      • 1970-01-01
      • 2021-10-13
      • 1970-01-01
      • 2018-11-29
      • 1970-01-01
      相关资源
      最近更新 更多