fragment lifecycle: when “ondestroy” and “ondestroyview” are not called?

前端 未结 1 1847
再見小時候
再見小時候 2020-11-28 11:47

Imagine this scenario: I have a Fragment in a Pager. I try to switch to other apps, so that the Activity owning my pager (and my fragm

相关标签:
1条回答
  • 2020-11-28 12:15

    Take a look at this question: Why implement onDestroy() if it is not guaranteed to be called?

    Basically, onDestroy() is only guaranteed to be called if you call finish(). Otherwise, onDestroy() may not be called until the system deems it necessary. You might want to look at putting your "closing" logic in the onPause() or onStop() instead.

    0 讨论(0)
提交回复
热议问题