是否保证可以调用Fragment.onStop()? [英] Is Fragment.onStop() guaranteed to be called?

查看:164
本文介绍了是否保证可以调用Fragment.onStop()?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在此链接的表中: http://developer. android.com/reference/android/app/Activity.html#ActivityLifecycle

我们可以看到,只有在调用onStop()之后(对于Honeycomb及更高版本),Android Activity才能被杀死.

我们对片段有相同的保证吗?

非常感谢有人将我指向明确说明的文档.

正如已经指出的,[Fragment.onStop]通常与包含的Activity生命周期的Activity.onStop相关.

http://developer.android.com/reference/android/app/Fragment.html#onStop()

但这并不能告诉我Fragment的onStop()得到了保证(至少没有达到Activity文档所提供的清晰度.)是否有明确声明Fragment.onStop()保证的地方? >

基于下面的讨论,我们现在讨论是否可以保证Activity.onStop()(假设可以肯定的是,如果不能,那么Fragment.onStop都不可以保证).我已将有关Activity.onStop的问题移至新线程:是否会确保Activity.onStop()被调用(API 11 +).

在我看来,必须保证Activity.onStop被调用,而Fragment.onStop也必须被保证.

解决方案

onStop()片段对用户不再可见,因为它的活动已停止或片段操作正在该活动中对其进行修改.

这通常与包含Activity生命周期的Activity.onStop相关.

http://developer.android.com/reference/android/app/Fragment.html#onStop()

在内存不足的情况下,不能同时保证活动和片段都将调用onStop()方法

请注意,在内存不足的情况下,如果系统的内存不足,无法在调用onPause()方法后保持活动的进程运行,则永远不会调用此方法.

http://developer.android.com/reference/android/app/Activity.html#Fragments

From the table at this link: http://developer.android.com/reference/android/app/Activity.html#ActivityLifecycle

we can see that an Android Activity is not killable until after onStop() has been called (for Honeycomb and beyond).

Do we have the same (documented) guarantee for Fragments?

Would greatly appreciate someone pointing me at documentation where it is clearly stated.

Edit: As has been pointed out [Fragment.onStop] is generally tied to Activity.onStop of the containing Activity's lifecycle.

http://developer.android.com/reference/android/app/Fragment.html#onStop()

But this doesn't tell me that Fragment's onStop() is guaranteed (at least not to the same level of clarity that the Activity documentation gives.) Is there anywhere that Fragment.onStop() guarantee is explicitly stated?

Edit 2: Based on the discussion below, we are now debating whether Activity.onStop() is guaranteed (it seems safe to assume that if not, then neither is Fragment.onStop guaranteed). I have moved the question about Activity.onStop to a new thread: Is Activity.onStop() guaranteed to be called (API 11 +).

It seems to me necessary, but not sufficient, that Activity.onStop is guaranteed to be called for Fragment.onStop to be also guaranteed.

解决方案

onStop() fragment is no longer visible to the user either because its activity is being stopped or a fragment operation is modifying it in the activity.

This is generally tied to Activity.onStop of the containing Activity's lifecycle.

http://developer.android.com/reference/android/app/Fragment.html#onStop()

In Low memory, it is not guaranteed for both activity and fragment will call onStop() method

Note that this method may never be called, in low memory situations where the system does not have enough memory to keep your activity's process running after its onPause() method is called.

http://developer.android.com/reference/android/app/Activity.html#Fragments

这篇关于是否保证可以调用Fragment.onStop()?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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