假设我添加了三个 fragment :
A
、B
和 C
在事务中,我提交了相同的内容。提交后,A
、B
和C
的onResume()
方法被依次调用。
然后,我进一步使用替换函数将其替换为第二个 fragment 的新实例。
我观察到的是:
FragmentA
被销毁
FragmentC
被销毁
FragmentB
正在调用 onStop()
而不是 onDestroy()
创建了一个新的 FragmentB
实例,并调用了它的 onCreate()
方法。
我的问题是为什么 FragmentB
的 onDestroy()
没有被调用?
最佳答案
onDestroy
不保证被调用。 Activity
和 Fragment
都是如此。
更多信息请看这里:
fragment lifecycle: when "ondestroy" and "ondestroyview" are not called?
Why implement onDestroy() if it is not guaranteed to be called?
关于android - fragment 管理器运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34528503/