【问题标题】:Fragment manager functioning片段管理器运行
【发布时间】:2015-12-30 11:20:07
【问题描述】:

假设我添加了三个片段: A、B 和 C 在一个事务中,我也提交了相同的内容。提交后,依次调用A、B、C的onResume()方法。

然后,我进一步使用替换功能将其替换为第二个片段的新实例。

我观察到的是: FragmentA 被销毁 FragmentC 被销毁 FragmentB 正在调用 onStop() 而不是 onDestroy()

创建FragmentB 的新实例并调用其onCreate() 方法。

我的问题是为什么onDestroy() for FragmentB 没有被调用?

【问题讨论】:

  • 这三个片段的替换片段的代码我能得到吗?

标签: android android-fragments


【解决方案1】:

onDestroy 不能保证被调用。 Activity 和 Fragment 都是如此。

查看这里了解更多信息:

fragment lifecycle: when "ondestroy" and "ondestroyview" are not called?

Why implement onDestroy() if it is not guaranteed to be called?

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-10-03
    • 2019-09-26
    • 2023-03-21
    相关资源
    最近更新 更多