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?
Asked
Active
Viewed 2.0k times
12

random.123
- 65
- 8

Haitham Haitham
- 157
- 1
- 1
- 6
-
Duplicate of: https://stackoverflow.com/questions/46814158/why-theres-a-separate-mutablelivedata-subclass-of-livedata – Metehan Toksoy Oct 12 '18 at 06:41
-
Use Live Data when you don't intend to modify it in the future otherwise Mutable Live Data – Tarun Sharma Nov 29 '20 at 07:35
1 Answers
9
LiveData
is immutable while MutableLiveData
is mutable. MutableLiveData
extends LiveData
and provides methods like setValue()
and postValue()
.

theanilpaudel
- 3,348
- 8
- 39
- 67
-
7`LiveData` provides methods `setValue()` and `postValue()` too but they are protected, not public – pskink Oct 12 '18 at 05:45
-
-
1
-
1@GeorgeUdosen Because they are available to the subclass (or creating classes like `MutableLiveData`) but are not part of the public interface. – Ellen Spertus Mar 10 '20 at 17:12