片段生命周期:当"的OnDestroy"和" ondestroyview"不叫? [英] fragment lifecycle: when "ondestroy" and "ondestroyview" are not called?

查看:149
本文介绍了片段生命周期:当"的OnDestroy"和" ondestroyview"不叫?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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?

推荐答案

看看这个问题:<一href="http://stackoverflow.com/questions/6117341/why-implement-ondestroy-if-it-is-not-guaranteed-to-be-called">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.

这篇关于片段生命周期:当&QUOT;的OnDestroy&QUOT;和&QUOT; ondestroyview&QUOT;不叫?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆