MutableLiveData
public class MutableLiveData<T> extends LiveData
MediatorLiveData |
|
LiveData which publicly exposes setValue and postValue method.
| Parameters | |
|---|---|
<T> |
The type of data hold by this instance |
Summary
Public constructors |
|---|
|
Creates a MutableLiveData with no value assigned to it. |
MutableLiveData(T value)Creates a MutableLiveData initialized with the given |
Public methods |
|
|---|---|
void |
postValue(T value)Posts a task to a main thread to set the given value. |
void |
setValue(T value)Sets the value. |
Inherited methods |
||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
Public constructors
MutableLiveData
public MutableLiveData()
Creates a MutableLiveData with no value assigned to it.
MutableLiveData
public MutableLiveData(T value)
Creates a MutableLiveData initialized with the given value.
| Parameters | |
|---|---|
T value |
initial value |
Public methods
postValue
public void postValue(T value)
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");If you called this method multiple times before a main thread executed a posted task, only the last value would be dispatched.
| Parameters | |
|---|---|
T value |
The new value |