LiveData which publicly exposes setValue(T) and postValue(T) method.
Questions tagged [mutablelivedata]
320 questions
192
votes
10 answers
Difference of setValue() & postValue() in MutableLiveData
There are two ways that make change value of MutableLiveData. But what is difference between setValue() & postValue() in MutableLiveData.
I could not find documentation for same.
Here is class MutableLiveData of Android.
package…

Khemraj Sharma
- 57,232
- 27
- 203
- 212
56
votes
16 answers
LiveData prevent receive the last value when start observing
Is it possible to prevent LiveData receive the last value when start observing?
I am considering to use LiveData as events.
For example events like show message, a navigation event or a dialog trigger, similar to EventBus.
The problem related to…

Pavel Poley
- 5,307
- 4
- 35
- 66
42
votes
8 answers
MutableLiveData not updating in UI
UPDATE:
If i move to another fragment and return to this one the TextView gets updated...
I am unable to get the MutableLiveData in the UI to update to a new value either by using setValue() or postValue(). I can get this to work by changing the…

DevinM
- 1,112
- 1
- 12
- 29
29
votes
3 answers
Is SingleLiveEvent actually part of the Android Architecture Components Library?
I have been using the SingleLiveData class which can be found here. My questions are:
Is SingleLiveData is actually part of the Android Architecture Components?
Is it a good idea to use it?

Archie G. Quiñones
- 11,638
- 18
- 65
- 107
20
votes
5 answers
How to emit distinct values from MutableLiveData?
I observed that MutableLiveData triggers onChanged of an observer even if the same object instance is provided to its setValue method.
//Fragment#onCreateView - scenario1
val newValue = "newValue"
mutableLiveData.setValue(newValue) //triggers…

Pravin Sonawane
- 1,803
- 4
- 18
- 32
16
votes
4 answers
How to Share Data between Activity and Fragment via ViewModel Class in Android?
I wondered if it's possible to pass a String data which has declared in Activity class and pass the String data to ViewModel class then pass the data to Fragment class.
ViewModel Class
class TimeTableViewModel extends ViewModel {
private…
user13024999
14
votes
2 answers
LiveData(MutableLiveData) and Databinding rise error (Failed to call observer method)
I have an app that uses ViewModel and MutableLiveData to bind live data to my UI. After hours westing my time! and review all sample on the internet I couldn't find the reason for the problem.
My activity:
public class DetailActivity extends…

Siamak Ferdos
- 3,181
- 5
- 29
- 56
12
votes
1 answer
Difference between LiveData, MutableLiveData
I know that the MutableLiveData extends LiveData,
but what is the difference between them (in usage). What are appropriate use cases, means when to use the correct one from the two?

Haitham Haitham
- 157
- 1
- 1
- 6
11
votes
2 answers
LiveData with multiple sources of different types
I currently have a project that contains a list of MyItem, and using Firebase/LiveData. It's structured into groups, and each group has items.
I want to be able to update this list if any of the following happen:
An item is updated (on the backend…

advice
- 5,778
- 10
- 33
- 60
7
votes
2 answers
MutableLiveData retains old value even when the observer activity gets destroyed
I have an activity which is observing livedata from repository. Now when the activity gets destroyed and then created again, i still get the old value from repository unless i fetch the new one manually.
Why is the mutablelivedata retaining its old…

Neelabh Anand
- 71
- 1
- 2
7
votes
2 answers
How to get result of two mutablelivedata into one
I have two variables in my ViewModel which are controlled by user with buttons. He can decrement or increment value by click on proper button.
val age = MutableLiveData().apply { value = 0 }
val weight = MutableLiveData().apply { value…

Remzo
- 149
- 3
- 12
6
votes
0 answers
How to share data between Activities with LiveData?
I have two Activity and one Fragment. I want to share data between these Activities. In fact, when the user changed FragemtA in MainActivity, must be update FragmentA in SecondActivity automatically.
My ViewModel: PlayerFragmentVM.java
public class…

ch65
- 321
- 3
- 8
6
votes
1 answer
How to observe the livedata with multiple observe for correct way in Android?
I have an Activity, and it will turn to the fragment-A and then turn to the fragment-B like the following.
Activity -> Fragment-A -> Fragment-B
situation 1
These two fragment observe the same LiveData for showing snackBar like the following…

Wun
- 6,211
- 11
- 56
- 101
6
votes
3 answers
Is it possible to increment mutablelivedata without additional variable?
I have simple view with edit text and 2 buttons and I want to give user ability to increse/decrese amount by 1 with buttons or he can manually write amount in edit text widget, but this value can't be less than 0 and greater than 10. I'm using MVVM…

Remzo
- 149
- 3
- 12
5
votes
0 answers
Unexpected failure during lint analysis since `androidx-livedata` update 2.3.0
While running lint a strange error occurred. This appears to happen after a androidx.lifecycle update from 2.2.0 to 2.3.0:
../../src/main/java/my/project/MyService.kt: Unexpected failure during lint analysis of MyService.kt
(this is a bug in lint or…

P Kuijpers
- 1,593
- 15
- 27