gpt4 book ai didi

android - fragment 生命周期 : when "ondestroy" and "ondestroyview" are not called?

转载 作者:IT老高 更新时间:2023-10-28 21:49:05 31 4
gpt4 key购买 nike

想象一下这个场景:我在 Pager 中有一个 Fragment。我尝试切换到其他应用程序,以便拥有我的寻呼机(和我的 fragment )的 Activity 最终将停止并暂时销毁。

所以,当我回到我的 Activity 时,会调用 Fragment 的回调 onCreateoncreateview 等等。但是之前没有调用 Fragment 的 onDestroy 回调!似乎在“onStop”之后 fragment 立即被销毁。这是正常行为吗?是不是因为 Activity 没有调用它的 onDestroy 就被销毁了?

最佳答案

看看这个问题:Why implement onDestroy() if it is not guaranteed to be called?

基本上,onDestroy() 只有在你调用 finish() 时才会被保证被调用。否则,在系统认为有必要之前,可能不会调用 onDestroy()。您可能希望将“关闭”逻辑放在 onPause() 或 onStop() 中。

关于android - fragment 生命周期 : when "ondestroy" and "ondestroyview" are not called?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17195641/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com