When would Fragment's onDestroyView be called, but it wouldn't be destroyed?
It seems to all depend on whether the fragment is retained or not. When the fragment is retained, then after onDestroyView comes onCreateView.
When the fragment is retained (i.e. setRetainInstance(true)), then the log while rotating the devicelooks like this:
com.example.FragmentLifecycleTestApp W/MainFragment﹕ onAttach
com.example.FragmentLifecycleTestApp W/MainFragment﹕ onCreate
com.example.FragmentLifecycleTestApp W/MainFragment﹕ onCreateView
com.example.FragmentLifecycleTestApp W/MainFragment﹕ onActivityCreated
com.example.FragmentLifecycleTestApp W/MainFragment﹕ onStart
com.example.FragmentLifecycleTestApp W/MainFragment﹕ onResume
com.example.FragmentLifecycleTestApp W/MainFragment﹕ onPause
com.example.FragmentLifecycleTestApp W/MainFragment﹕ onStop
com.example.FragmentLifecycleTestApp W/MainFragment﹕ onDestroyView
com.example.FragmentLifecycleTestApp W/MainFragment﹕ onDetach
com.example.FragmentLifecycleTestApp W/MainFragment﹕ onAttach
com.example.FragmentLifecycleTestApp W/MainFragment﹕ onCreateView
com.example.FragmentLifecycleTestApp W/MainFragment﹕ onActivityCreated
com.example.FragmentLifecycleTestApp W/MainFragment﹕ onStart
com.example.FragmentLifecycleTestApp W/MainFragment﹕ onResume
But when it is not retained, it goes like this:
com.example.FragmentLifecycleTestApp W/MainFragment﹕ onAttach
com.example.FragmentLifecycleTestApp W/MainFragment﹕ onCreate
com.example.FragmentLifecycleTestApp W/MainFragment﹕ onCreateView
com.example.FragmentLifecycleTestApp W/MainFragment﹕ onActivityCreated
com.example.FragmentLifecycleTestApp W/MainFragment﹕ onStart
com.example.FragmentLifecycleTestApp W/MainFragment﹕ onResume
com.example.FragmentLifecycleTestApp W/MainFragment﹕ onPause
com.example.FragmentLifecycleTestApp W/MainFragment﹕ onStop
com.example.FragmentLifecycleTestApp W/MainFragment﹕ onDestroyView
com.example.FragmentLifecycleTestApp W/MainFragment﹕ onDestroy
com.example.FragmentLifecycleTestApp W/MainFragment﹕ onDetach
com.example.FragmentLifecycleTestApp W/MainFragment﹕ onAttach
com.example.FragmentLifecycleTestApp W/MainFragment﹕ onCreate
com.example.FragmentLifecycleTestApp W/MainFragment﹕ onCreateView
com.example.FragmentLifecycleTestApp W/MainFragment﹕ onActivityCreated
com.example.FragmentLifecycleTestApp W/MainFragment﹕ onStart
com.example.FragmentLifecycleTestApp W/MainFragment﹕ onResume
Take a look on the diagram:
This is the explicit visualization of all lifecycle states. Enjoy.