【问题标题】:Statically added Fragment can't restore instance state?静态添加的 Fragment 无法恢复实例状态?
【发布时间】:2018-12-10 08:44:06
【问题描述】:

当我在 Activity 布局中静态添加 Fragment 时,即使正确调用了 onSaveInstanceState(outState: Bundle),我似乎也无法恢复 onViewStateRestored(savedInstanceState: Bundle) 中的状态。

当我动态添加它时,它适用于同一个片段。

这根本不可能做到这一点,还是需要在 Manifest 或 w/e 中进行额外配置

编辑: onViewStateRestored(savedInstanceState: Bundle) 将被调用,但 Bundle 为空,以及传递 Bundle 的其他生命周期回调

【问题讨论】:

  • 发布源代码

标签: android android-lifecycle activity-lifecycle fragment-lifecycle


【解决方案1】:

您还应该在添加片段的位置发布代码,但不确定静态添加片段是什么意思。

请同时查看以下答案:

如果还是不明白,请粘贴您的代码。

【讨论】:

    猜你喜欢
    • 2013-04-15
    • 1970-01-01
    • 2021-03-18
    • 1970-01-01
    • 2021-09-18
    • 1970-01-01
    • 2019-01-21
    • 1970-01-01
    • 2012-11-12
    相关资源
    最近更新 更多