CompositionLifecycleObserver

interface CompositionLifecycleObserver

Objects implementing this interface are notified when they are initially used in a composition and when they are no longer being used.

An object enters the composition if it is remembered in at least one place in a composition. Compose may implicitly remember an object if doing so is required to restart the composition later, such as for composable function parameters. An object leaves a composition when it is no longer remembered anywhere in that composition.

Implementations of CompositionLifecycleObserver should generally not expose those object references outside of their immediate usage sites. A CompositionLifecycleObserver reference that is propagated to multiple parts of a composition might remain present in the composition for longer than expected if it is remembered (explicitly or implicitly) elsewhere in the same composition, and a CompositionLifecycleObserver that appears in more than one composition may have its lifecycle callback methods called multiple times in no meaningful order and on multiple threads. Implementations intending to support this use case should implement atomic reference counting or a similar strategy to correctly manage resources.

Functions

equals
Link copied to clipboard
common
open operator fun equals(other: Any?): Boolean
hashCode
Link copied to clipboard
common
open fun hashCode(): Int
onEnter
Link copied to clipboard
common
open fun onEnter()
Called when this object successfully enters a composition.
onLeave
Link copied to clipboard
common
open fun onLeave()
Called when this object leaves a composition.
toString
Link copied to clipboard
common
open fun toString(): String