MutableLiveData
is essentially a LiveData
with public access to two methods setValue()
and postValue()
for modifying that data.
Therefore, MutableLiveData
is needed if you plan to modify the values of the LiveData.
However, in programming, it's a common concept to make your variables immutable or restrict the access of those who can modify the data of an object. You wouldn't want to expose the ability to modify the contents of variables within an object if there's no need to do so.
Therefore, for MutableLiveData
, we normally use a getter to get it's parent form, which is LiveData
.
By getting only LiveData
, we can ensure that those who access the LiveData
object can only read the values stored within with no ability to change them.
In a sense, it's just the concept of why you should use private variables with getters.