Is Fragment.onStop() guaranteed to be called?

情到浓时终转凉″ 提交于 2019-12-09 13:23:08

问题


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.


回答1:


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



来源:https://stackoverflow.com/questions/29390760/is-fragment-onstop-guaranteed-to-be-called

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!