LifecycleRegistry

open class LifecycleRegistry
kotlin.Any
   ↳ androidx.lifecycle.LifecycleRegistry

An implementation of Lifecycle that can handle multiple observers.

It is used by Fragments and Support Library Activities. You can also directly use it if you have a custom LifecycleOwner.

Summary

Public constructors

Creates a new LifecycleRegistry for the given provider.

Public methods
open Unit

open Unit

open Unit
markState(state: State)

Moves the Lifecycle to the given state and dispatches necessary events to the observers.

open Int

The number of observers.

open Unit

Sets the current state and notifies the observers.

open State

Public constructors

<init>

LifecycleRegistry(provider: LifecycleOwner)

Creates a new LifecycleRegistry for the given provider.

You should usually create this inside your LifecycleOwner class's constructor and hold onto the same instance.

Parameters
provider LifecycleOwner: The owner LifecycleOwner

Public methods

addObserver

open fun addObserver(observer: LifecycleObserver): Unit

removeObserver

open fun removeObserver(observer: LifecycleObserver): Unit

markState

open fun markState(state: State): Unit

Moves the Lifecycle to the given state and dispatches necessary events to the observers.

Parameters
state State: new state

getObserverCount

open fun getObserverCount(): Int

The number of observers.

Return
Int: The number of observers.

handleLifecycleEvent

open fun handleLifecycleEvent(event: Lifecycle.Event): Unit

Sets the current state and notifies the observers.

Note that if the currentState is the same state as the last call to this method, calling this method has no effect.

Parameters
event Lifecycle.Event: The event that was received

getCurrentState

open fun getCurrentState(): State