[ Web Proxy ]
URL:
Viewing: https://developer.android.com/reference/androidx/lifecycle/MutableLiveData [Back]  [Original]

MutableLiveData  |  API reference  |  Android Developers Skip to main content
Essentials Design & Plan Develop Google Play Blog
Search:
Android Studio
Android Developers [Android Developers]
Stay organized with collections Save and categorize content based on your preferences.

MutableLiveData


public class MutableLiveData<T> extends LiveData

java.lang.Object
    androidx.lifecycle.LiveData
      androidx.lifecycle.MutableLiveData
Known direct subclasses
MediatorLiveData

LiveData subclass which may observe other LiveData objects and react on OnChanged events from them.


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 value.

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 androidx.lifecycle.LiveData
@Nullable T

Returns the current value.

boolean

Returns true if this LiveData has active observers.

boolean

Returns true if this LiveData has observers.

boolean

Returns whether an explicit value has been set on this LiveData.

void

Adds the given observer to the observers list within the lifespan of the given owner.

void

Adds the given observer to the observers list.

void

Called when the number of active observers change from 0 to 1.

void

Called when the number of active observers change from 1 to 0.

void

Removes the given observer from the observers list.

void

Removes all observers that are tied to the given LifecycleOwner.

Public constructors

MutableLiveData

Added in 2.0.0
public MutableLiveData()

Creates a MutableLiveData with no value assigned to it.

MutableLiveData

Added in 2.1.0
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");
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.

Parameters
T value

The new value

setValue

public 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

Parameters
T value

The new value

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 2026-06-24 UTC.

[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2026-06-24 UTC."],[],[]]

Web Proxy Viewer  |  New URL  |  Original Page