belongs to Maven artifact android.arch.lifecycle:livedata-core:1.1.1
MutableLiveData
public
class
MutableLiveData
extends LiveData<T>
LiveData subclass which may observe other LiveData objects and react on
OnChanged events from them.
LiveData which publicly exposes setValue(T) and postValue(T) method.
Summary
Public constructors | |
|---|---|
MutableLiveData()
|
|
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 | |
|---|---|
|
From class
android.arch.lifecycle.LiveData
void
observe(LifecycleOwner owner, Observer<T> observer)
Adds the given observer to the observers list within the lifespan of the given owner.
void
removeObservers(LifecycleOwner owner)
Removes all observers that are tied to the given | |
|
From class
java.lang.Object
Object
clone()
boolean
equals(Object arg0)
void
finalize()
final
Class<?>
getClass()
int
hashCode()
final
void
notify()
final
void
notifyAll()
String
toString()
final
void
wait(long arg0, int arg1)
final
void
wait(long arg0)
final
void
wait()
| |
Public constructors
Public methods
postValue
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 | |
|---|---|
value |
T: The new value
|
setValue
void setValue (T value)
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 postValue(Object)
| Parameters | |
|---|---|
value |
T: The new value
|
Annotations
Interfaces
Classes
- AndroidViewModel
- Lifecycle
- LifecycleRegistry
- LifecycleService
- LiveData
- LiveDataReactiveStreams
- MediatorLiveData
- MutableLiveData
- ProcessLifecycleOwner
- ServiceLifecycleDispatcher
- Transformations
- ViewModel
- ViewModelProvider
- ViewModelProvider.AndroidViewModelFactory
- ViewModelProvider.NewInstanceFactory
- ViewModelProviders
- ViewModelProviders.DefaultFactory
- ViewModelStore
- ViewModelStores
Enums
Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
Last updated 2025年02月10日 UTC.