LifecycleEventEffect

fun LifecycleEventEffect(event: Lifecycle.Event, lifecycleOwner: LifecycleOwner = LocalLifecycleOwner.current, onEvent: () -> Unit)(source)

Schedule an effect to run when the Lifecycle receives a specific Lifecycle.Event.

Using a Lifecycle.Observer to listen for when LifecycleEventEffect enters the composition, onEvent will be launched when receiving the specified event.

This function should not be used to listen for Lifecycle.Event.ON_DESTROY because Compose stops recomposing after receiving a Lifecycle.Event.ON_STOP and will never be aware of an ON_DESTROY to launch onEvent.

This function should also not be used to launch tasks in response to callback events by way of storing callback data as a Lifecycle.State in a MutableState. Instead, see currentStateAsState to obtain a State that may be used to launch jobs in response to state changes.

Parameters

event

The Lifecycle.Event to listen for

lifecycleOwner

The lifecycle owner to attach an observer

onEvent

The effect to be launched when we receive an event callback

Throws