LiveDataUtil

Utility class for adding one time observers to LiveData.

Functions

Link copied to clipboard
fun <T> observeOnce(liveData: LiveData<T>, observer: Observer<T>)

Observes an event from LiveData once, then it removes the observer. The method is not lifecycle aware, and so the observer needs to be manually removed if stopping before receiving a result.

fun <T> observeOnce(liveData: LiveData<T>, lifecycleOwner: LifecycleOwner, observer: Observer<T>)

Observes an event from LiveData once, then it removes the observer.

Link copied to clipboard
fun <T> updateValue(mutableLiveData: MutableLiveData<T>, newValue: T)

Updates the value of the MutableLiveData in the best way possible to propagate the results as faster.