observeOnce

inline fun <T> LiveData<T>.observeOnce(lifecycleOwner: LifecycleOwner, crossinline onChanged: (T) -> Unit): Observer<T>

Observes this LiveData for one change only and returns the one-time observer. The returned observer can be used to stop observing the LiveData when a callback is no longer desired. It is safe to remove the observer while it is executing or has been executed already.

Parameters

lifecycleOwner

The owner of the observer.

onChanged

Called once with one change only.