Skip to content

Most visited

Recently visited

added in version 1.0.0
belongs to Maven artifact android.arch.lifecycle:livedata-core:1.1.0


public class MutableLiveData
extends LiveData<T>

   ↳ android.arch.lifecycle.LiveData<T>
     ↳ android.arch.lifecycle.MutableLiveData<T>
Known Direct Subclasses

LiveData which publicly exposes setValue(T) and postValue(T) method.


Public constructors


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
From class java.lang.Object

Public constructors


added in version 1.0.0
MutableLiveData ()

Public methods


added in version 1.0.0
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:

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.

value T: The new value


added in version 1.0.0
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)

value T: The new value

This site uses cookies to store your preferences for site-specific language and display options.

Get the latest Android developer news and tips that will help you find success on Google Play.

* Required Fields


Follow Google Developers on WeChat

Browse this site in ?

You requested a page in , but your language preference for this site is .

Would you like to change your language preference and browse this site in ? If you want to change your language preference later, use the language menu at the bottom of each page.

This class requires API level or higher

This doc is hidden because your selected API level for the documentation is . You can change the documentation API level with the selector above the left navigation.

For more information about specifying the API level your app requires, read Supporting Different Platform Versions.

Take a short survey?
Help us improve the Android developer experience. (Dec 2017 Android Platform & Tools Survey)