Android fragments lifecycle onStop, onDestroyView, onDestroy and onDetach

允我心安 提交于 2020-01-02 06:39:10

问题


Android documentation talks about onStop an onDestroy couldn't be called in some circustances, but i didn't find nothing about the same with fragments. Is onPause, onStop, onDestroyView, on Destroy and onDetach always called? Only on Pause?


回答1:


It's the same for Fragments, so only onPause is always called.

Most of these callbacks are called at the same time (before or after to be exact) corresponding callbacks from Activity are called, when the fragment is added via xml layout.

Note that on newer versions of Android onStop is also always called.

Android documentation talks about onStop an onDestroy couldn't be called in some circustances

Just to make it clear: "some circustances" means your application process being killed by the user or by the system (usually when low on memory or application in background for a longer time).



来源:https://stackoverflow.com/questions/17258817/android-fragments-lifecycle-onstop-ondestroyview-ondestroy-and-ondetach

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