abstract class LifecycleAwareListeners<T>

LifecycleAwareListeners is a container for listeners with Android Lifecycle awareness.

It forwards events to registered listeners, depending on their lifecycle state. Events are forwarded to regular listeners when their lifecycle owner is active. Events for forever listeners are always received.

Lifecycle owners are considered active when their state is Lifecycle.State.STARTED or Lifecycle.State.RESUMED.

Listeners will be removed automatically when their lifecycle owner's state becomes Lifecycle.State.DESTROYED.



Link copied to clipboard


Link copied to clipboard

true when at least one of the registered listeners is active; false otherwise.


Link copied to clipboard
fun addListener(lifecycleOwner: LifecycleOwner, listener: T)

Add a listener that will receive events when its LifecycleOwner is active.

Link copied to clipboard
fun addListenerForever(listener: T)

Add a listener that will always receive events.

Link copied to clipboard
fun removeListener(listener: T)

Remove listener.

Link copied to clipboard

Remove all listeners registered with a lifecycle owner.