class SingleLiveData<T> : MutableLiveData<T>
A lifecycle-aware observable that sends only new updates after subscription, used for events like navigation and Snackbar messages.
This avoids a common problem with events: on configuration change (like rotation) an update can be emitted if the observer is active. This LiveData only calls the observable if there's an explicit call to setValue() or call().
Note that only one observer is going to be notified of changes.
See Also
<init> |
A lifecycle-aware observable that sends only new updates after subscription, used for events like navigation and Snackbar messages. SingleLiveData() |
observe |
Adds the given observer to the observers list within the lifespan of the given owner. The events are dispatched on the main thread. If LiveData already has data set, it will be delivered to the observer. fun observe(owner: LifecycleOwner, observer: Observer<in T>): Unit |
setValue |
Sets the value. If there are active observers, the value will be dispatched to them. fun setValue(value: T?): Unit |