Android fragments lifecycle onStop, onDestroyView,

2019-05-07 17:56发布

问题:

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).