rememberLifecycleEvent

fun rememberLifecycleEvent(lifecycleOwner: LifecycleOwner = LocalLifecycleOwner.current): Lifecycle.Event

Remembers the current lifecycle event and updates it as the lifecycle changes.

This Composable function observes the lifecycle of the provided lifecycleOwner (defaulting to the LocalLifecycleOwner) and returns the latest Lifecycle.Event. The returned event will trigger recomposition when it changes.

This is useful for performing actions or updating UI based on the current lifecycle state of a component (e.g., an Activity or Fragment).

The observer is automatically added when the Composable enters the composition and removed when it leaves, preventing memory leaks.

Return

The current Lifecycle.Event. Initially Lifecycle.Event.ON_ANY, then updates as lifecycle events occur.

Parameters

lifecycleOwner

The LifecycleOwner whose lifecycle events are to be observed. Defaults to LocalLifecycleOwner.current.