SubLifecycleOwner

class SubLifecycleOwner(parentLifecycleOwner: LifecycleOwner) : LifecycleOwner

An owner of a sub-lifecycle of the given parentLifecycleOwner. The state of the sub-lifecycle is always in a state that is at most the parentLifecycleOwner's state. It can be a lower state either due to being limited with stateLimit or if the sub-lifecycle is destroyed.

The stateLimit allows the sub-lifecycle state, for instance, to remain in the State.CREATED state when parentLifecycleOwner's state is State.STARTED or State.RESUMED.

The sub-lifecycle owner may be destroyed sooner than the destruction of parentLifecycleOwner.

Constructors

Link copied to clipboard
fun SubLifecycleOwner(parentLifecycleOwner: LifecycleOwner)

Properties

Link copied to clipboard
var stateLimit: Lifecycle.State? = null

Limits the states of this lifecycle owner to the given value.

Functions

Link copied to clipboard
fun destroy()

Moves the sub-lifecycle owner to the destroyed state. After this call, it will no longer follow the lifecycle of its parent.

Link copied to clipboard
open override fun getLifecycle(): Lifecycle