Package icyllis.modernui.lifecycle
Class MutableLiveData<T>
java.lang.Object
icyllis.modernui.lifecycle.LiveData<T>
icyllis.modernui.lifecycle.MutableLiveData<T>
- Type Parameters:
T
- The type of data hold by this instance
- Direct Known Subclasses:
MediatorLiveData
-
Constructor Summary
ConstructorDescriptionCreates a MutableLiveData with no value assigned to it.MutableLiveData
(T value) Creates a MutableLiveData initialized with the givenvalue
. -
Method Summary
Methods inherited from class icyllis.modernui.lifecycle.LiveData
getValue, hasActiveObservers, hasObservers, observe, observeForever, onActive, onInactive, removeObserver, removeObservers
-
Constructor Details
-
MutableLiveData
Creates a MutableLiveData initialized with the givenvalue
.- Parameters:
value
- initial value
-
MutableLiveData
public MutableLiveData()Creates a MutableLiveData with no value assigned to it.
-
-
Method Details
-
postValue
Description copied from class:LiveData
Posts a task to a main thread to set the given value. So if you have a following code executed in the main thread:liveData.postValue("a"); liveData.setValue("b");
The value "b" would be set at first and later the main thread would override it with the value "a".If you called this method multiple times before a main thread executed a posted task, only the last value would be dispatched.
-
setValue
Description copied from class:LiveData
Sets the value. If there are active observers, the value will be dispatched to them.This method must be called from the main thread. If you need set a value from a background thread, you can use
LiveData.postValue(Object)
-