LifecycleAwareListeners

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.

Constructors

Link copied to clipboard
fun LifecycleAwareListeners()

Properties

Link copied to clipboard
val active: LiveData<Boolean>

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

Functions

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
fun removeListeners(owner: LifecycleOwner)

Remove all listeners registered with a lifecycle owner.

Inheritors

Link copied to clipboard