added in [version 1.0.0](https://developer.android.com/topic/libraries/support-library/revisions)   
belongs to Maven artifact android.arch.lifecycle:livedata-core:1.1.1 Summary: [Ctors](https://developer.android.com/reference/android/arch/lifecycle/MutableLiveData#pubctors) \| [Methods](https://developer.android.com/reference/android/arch/lifecycle/MutableLiveData#pubmethods) \| [Inherited Methods](https://developer.android.com/reference/android/arch/lifecycle/MutableLiveData#inhmethods)

# MutableLiveData

| The `android.arch` Architecture Components packages are no longer maintained. They have been superseded by the corresponding [androidx.\*](https://developer.android.com/jetpack/androidx/migrate) packages. See [androidx.lifecycle.MutableLiveData](https://developer.android.com/reference/androidx/lifecycle/MutableLiveData) instead.


`
public


class
MutableLiveData
`


`


`

`

extends https://developer.android.com/reference/android/arch/lifecycle/LiveData<T>


`

`


`

|---|---|---|
| java.lang.Object |||
| ↳ | [android.arch.lifecycle.LiveData](https://developer.android.com/reference/android/arch/lifecycle/LiveData)\<T\> ||
|   | ↳ | android.arch.lifecycle.MutableLiveData\<T\> |

|---|
| Known direct subclasses [MediatorLiveData](https://developer.android.com/reference/android/arch/lifecycle/MediatorLiveData)\<T\> |---|---| | [MediatorLiveData](https://developer.android.com/reference/android/arch/lifecycle/MediatorLiveData)\<T\> | `https://developer.android.com/reference/android/arch/lifecycle/LiveData` subclass which may observe other `LiveData` objects and react on `OnChanged` events from them. | |

<br />

*** ** * ** ***

`https://developer.android.com/reference/android/arch/lifecycle/LiveData` which publicly exposes `https://developer.android.com/reference/android/arch/lifecycle/MutableLiveData#setValue(T)` and `https://developer.android.com/reference/android/arch/lifecycle/MutableLiveData#postValue(T)` method.

## Summary

| ### Public constructors ||
|---|---|
| ` https://developer.android.com/reference/android/arch/lifecycle/MutableLiveData#MutableLiveData()() ` |

| ### Public methods ||
|---|---|
| ` void` | ` https://developer.android.com/reference/android/arch/lifecycle/MutableLiveData#postValue(T)(T value) ` Posts a task to a main thread to set the given value. |
| ` void` | ` https://developer.android.com/reference/android/arch/lifecycle/MutableLiveData#setValue(T)(T value) ` Sets the value. |

| ### Inherited methods |
|---|---|
| From class ` https://developer.android.com/reference/android/arch/lifecycle/LiveData ` |---|---| | ` T` | ` https://developer.android.com/reference/android/arch/lifecycle/LiveData#getValue()() ` Returns the current value. | | ` boolean` | ` https://developer.android.com/reference/android/arch/lifecycle/LiveData#hasActiveObservers()() ` Returns true if this LiveData has active observers. | | ` boolean` | ` https://developer.android.com/reference/android/arch/lifecycle/LiveData#hasObservers()() ` Returns true if this LiveData has observers. | | ` void` | ` https://developer.android.com/reference/android/arch/lifecycle/LiveData#observe(android.arch.lifecycle.LifecycleOwner, android.arch.lifecycle.Observer<T>)(https://developer.android.com/reference/android/arch/lifecycle/LifecycleOwner owner, https://developer.android.com/reference/android/arch/lifecycle/Observer<T> observer) ` Adds the given observer to the observers list within the lifespan of the given owner. | | ` void` | ` https://developer.android.com/reference/android/arch/lifecycle/LiveData#observeForever(android.arch.lifecycle.Observer<T>)(https://developer.android.com/reference/android/arch/lifecycle/Observer<T> observer) ` Adds the given observer to the observers list. | | ` void` | ` https://developer.android.com/reference/android/arch/lifecycle/LiveData#onActive()() ` Called when the number of active observers change to 1 from 0. | | ` void` | ` https://developer.android.com/reference/android/arch/lifecycle/LiveData#onInactive()() ` Called when the number of active observers change from 1 to 0. | | ` void` | ` https://developer.android.com/reference/android/arch/lifecycle/LiveData#postValue(T)(T value) ` Posts a task to a main thread to set the given value. | | ` void` | ` https://developer.android.com/reference/android/arch/lifecycle/LiveData#removeObserver(android.arch.lifecycle.Observer<T>)(https://developer.android.com/reference/android/arch/lifecycle/Observer<T> observer) ` Removes the given observer from the observers list. | | ` void` | ` https://developer.android.com/reference/android/arch/lifecycle/LiveData#removeObservers(android.arch.lifecycle.LifecycleOwner)(https://developer.android.com/reference/android/arch/lifecycle/LifecycleOwner owner) ` Removes all observers that are tied to the given `https://developer.android.com/reference/android/arch/lifecycle/LifecycleOwner`. | | ` void` | ` https://developer.android.com/reference/android/arch/lifecycle/LiveData#setValue(T)(T value) ` Sets the value. | ||
| 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

### MutableLiveData

added in [version 1.0.0](https://developer.android.com/topic/libraries/support-library/revisions)

```
MutableLiveData ()
```

<br />

<br />

## Public methods

### postValue

added in [version 1.0.0](https://developer.android.com/topic/libraries/support-library/revisions)

```
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:

```text
 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.

<br />

| Parameters ||
|---|---|
| `value` | `T`: The new value <br /> |

### setValue

added in [version 1.0.0](https://developer.android.com/topic/libraries/support-library/revisions)

```
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 `https://developer.android.com/reference/android/arch/lifecycle/LiveData#postValue(T)`

<br />

| Parameters ||
|---|---|
| `value` | `T`: The new value <br /> |

-

  ## Annotations

  - [OnLifecycleEvent](https://developer.android.com/reference/android/arch/lifecycle/OnLifecycleEvent)
-

  ## Interfaces

  - [DefaultLifecycleObserver](https://developer.android.com/reference/android/arch/lifecycle/DefaultLifecycleObserver)
  - [LifecycleObserver](https://developer.android.com/reference/android/arch/lifecycle/LifecycleObserver)
  - [LifecycleOwner](https://developer.android.com/reference/android/arch/lifecycle/LifecycleOwner)
  - [LifecycleRegistryOwner](https://developer.android.com/reference/android/arch/lifecycle/LifecycleRegistryOwner)
  - [Observer](https://developer.android.com/reference/android/arch/lifecycle/Observer)
  - [ViewModelProvider.Factory](https://developer.android.com/reference/android/arch/lifecycle/ViewModelProvider.Factory)
  - [ViewModelStoreOwner](https://developer.android.com/reference/android/arch/lifecycle/ViewModelStoreOwner)
-

  ## Classes

  - [AndroidViewModel](https://developer.android.com/reference/android/arch/lifecycle/AndroidViewModel)
  - [Lifecycle](https://developer.android.com/reference/android/arch/lifecycle/Lifecycle)
  - [LifecycleRegistry](https://developer.android.com/reference/android/arch/lifecycle/LifecycleRegistry)
  - [LifecycleService](https://developer.android.com/reference/android/arch/lifecycle/LifecycleService)
  - [LiveData](https://developer.android.com/reference/android/arch/lifecycle/LiveData)
  - [LiveDataReactiveStreams](https://developer.android.com/reference/android/arch/lifecycle/LiveDataReactiveStreams)
  - [MediatorLiveData](https://developer.android.com/reference/android/arch/lifecycle/MediatorLiveData)
  - [MutableLiveData](https://developer.android.com/reference/android/arch/lifecycle/MutableLiveData)
  - [ProcessLifecycleOwner](https://developer.android.com/reference/android/arch/lifecycle/ProcessLifecycleOwner)
  - [ServiceLifecycleDispatcher](https://developer.android.com/reference/android/arch/lifecycle/ServiceLifecycleDispatcher)
  - [Transformations](https://developer.android.com/reference/android/arch/lifecycle/Transformations)
  - [ViewModel](https://developer.android.com/reference/android/arch/lifecycle/ViewModel)
  - [ViewModelProvider](https://developer.android.com/reference/android/arch/lifecycle/ViewModelProvider)
  - [ViewModelProvider.AndroidViewModelFactory](https://developer.android.com/reference/android/arch/lifecycle/ViewModelProvider.AndroidViewModelFactory)
  - [ViewModelProvider.NewInstanceFactory](https://developer.android.com/reference/android/arch/lifecycle/ViewModelProvider.NewInstanceFactory)
  - [ViewModelProviders](https://developer.android.com/reference/android/arch/lifecycle/ViewModelProviders)
  - [ViewModelProviders.DefaultFactory](https://developer.android.com/reference/android/arch/lifecycle/ViewModelProviders.DefaultFactory)
  - [ViewModelStore](https://developer.android.com/reference/android/arch/lifecycle/ViewModelStore)
  - [ViewModelStores](https://developer.android.com/reference/android/arch/lifecycle/ViewModelStores)
-

  ## Enums

  - [Lifecycle.Event](https://developer.android.com/reference/android/arch/lifecycle/Lifecycle.Event)
  - [Lifecycle.State](https://developer.android.com/reference/android/arch/lifecycle/Lifecycle.State)