Search code examples
androidandroid-fragmentsfragment-lifecycle

When will onResume() be called without onStart() being called first (Fragment Lifecycle)


onStart() is when the Fragment becomes visible, onResume() is when the Fragment becomes interactive. So when will the onResume() -> onPause() -> onResume() cycle execute without executing the encompassing onStart() -> onStop() cycle?

In terms of fragment transitions, a replace will destroy the starting fragment, calling its onPause() -> onStop() as well as other destroy related life-cycle methods. If the transition is replace but add the starting fragment to **backStack**, it will still call onPause() -> onStop() except without completely destroying the fragment and detaching it from activity. In the case of just overlaying another fragment, none of the starting fragment's lifecycle events are executed because its still there just not visible (another fragment getting drawn over it).

I'm not sure when onResume() will ever be called without onStart(), as well as onPause() with onStop().

Edit: Along with the answers already here, using android split screen would also pause the fragment without stopping it.


Solution

  • When your activity stays visible while showing a dialog or another activity is shown on top that has transparency.

    Basically your activity is visible between onStart()and onStop() and your activity is interactive between onResume() and onPause(). When it it becomes uninteractive while staying visible you will get onPause without onStop.