DistinctMutableLiveData

class DistinctMutableLiveData<T> : MutableLiveData<T>

An implementation of MutableLiveData that only emits updates when the value actually changed, i.e. when newValue != oldValue. This differs from regular MutableLiveData because if you set its value to an equal same value, it still emits an update, causing observers to get a callback.

This is more suitable than the distinctUntilChanged transformation for the cases where the values are not necessarily going to be observed: distinctUntilChanged only changes value when observers are registered.

NB: This should only be used in situations where it's guaranteed to not lead to side-effects. The most common situation where this should not be used is for instances of T that are both mutable and have a custom Object.equals implementation. This could lead to situations where a set value is ignored but mutated afterwards, meaning the value shouldn't have been ignored after all. As a guideline, only use DistinctMutableLiveData for types that could also be used as a key in a Map.

Constructors

Link copied to clipboard
fun DistinctMutableLiveData()
Link copied to clipboard
fun <T> DistinctMutableLiveData(value: T)

Inherited properties

Link copied to clipboard
val mActiveCount: Int
Link copied to clipboard
val mDataLock: Any
Link copied to clipboard
val mPendingData: Any

Functions

Link copied to clipboard
open override fun setValue(newValue: T?)

Inherited functions

Link copied to clipboard
open fun changeActiveCounter(p0: Int)
Link copied to clipboard
open fun dispatchingValue(@Nullable p0: LiveData.ObserverWrapper<T>?)
Link copied to clipboard
open fun getValue(): T?
Link copied to clipboard
open fun getVersion(): Int
Link copied to clipboard
open fun hasActiveObservers(): Boolean
Link copied to clipboard
open fun hasObservers(): Boolean
Link copied to clipboard
open fun observe(@NonNull p0: LifecycleOwner, @NonNull p1: Observer<in T>)
Link copied to clipboard
open fun observeForever(@NonNull p0: Observer<in T>)
Link copied to clipboard
open fun onActive()
Link copied to clipboard
open fun onInactive()
Link copied to clipboard
open override fun postValue(p0: T)
Link copied to clipboard
open fun removeObserver(@NonNull p0: Observer<in T>)
Link copied to clipboard
open fun removeObservers(@NonNull p0: LifecycleOwner)