片段生命周期:当"的OnDestroy"和" ondestroyview"不叫?不叫、生命周期、片段、QUOT

由网友(少在我面前 装斯文)分享简介:想象一下这样的情景:我有一个片段在寻呼机。我尝试切换到其他应用程序,从而使活动拥有我的传呼机(和我的片段)将被停止,暂时遭到破坏,最终。Imagine this scenario: I have a Fragment in a Pager. I try to switch to other apps, so that...

想象一下这样的情景:我有一个片段寻呼机。我尝试切换到其他应用程序,从而使活动拥有我的传呼机(和我的片段)将被停止,暂时遭到破坏,最终。

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 fragment) will be stopped and temporarily destroyed, eventually.

所以,当我回到我的活动,在片段的回调的onCreate oncreateview 等被调用。但没有一个片段的的onDestroy 的回调被调用之前!看来以后的onStop的片段在一旦遭到破坏。它是一个正常的行为?是不是也许因为活动不调用被销毁了的onDestroy

So, when I come back to my Activity, the Fragment's callbacks onCreate, oncreateview and so forth are called. But none of the Fragment's onDestroy callbacks were called before! It seems that after "onStop" the fragment is destroyed at once. Is it a normal behavior? Is it maybe because the Activity is destroyed without a call to its onDestroy?

推荐答案

看看这个问题:Why实施的onDestroy(),如果它不能保证被称为?

基本上的onDestroy()时,才能保证如果调用完成被称为()。否则,的onDestroy()可能不被调用,直到系统认为有必要的。你可能想看看把你的收的逻辑中的onPause()或的onStop()来代替。

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.

阅读全文

相关推荐

最新文章