handleLifecycleEventInSteps

fun LifecycleRegistry.handleLifecycleEventInSteps(event: Lifecycle.Event)

Updates the LifecycleRegistry's state according to the event. This can be used instead of the default LifecycleRegistry.handleLifecycleEvent to update each LifecycleObserver for every step in the state change.

For example, this function will lead to the following behaviour:

// GIVEN
lifecycleRegistry.currentState = State.CREATED
lifecycleRegistry.addObserver(observer1)
lifecycleRegistry.addObserver(observer2)

// WHEN
lifecycleRegistry.handleLifecycleEventInSteps(Event.ON_RESUMED)

// THEN callback will be in order:
// observer1.onStart()
// observer2.onStart()
// observer1.onResume()
// observer2.onResume()

When using the default LifecycleRegistry.handleLifecycleEvent, then callbacks will be in this order instead:

// observer1.onStart()
// observer1.onResume()
// observer2.onStart()
// observer2.onResume()

The default behaviour can be problematic if one of the observer's lifecycle impacts another.