When to use MutableLiveData and LiveData

LiveData has no public method to modify its data.

LiveData<User> getUser() {
    if (userMutableLiveData == null) {
        userMutableLiveData = new MutableLiveData<>();
    }
    return userMutableLiveData
}

You can’t update its value like getUser().setValue(userObject) or getUser().postValue(userObject)

So when you don’t want your data to be modified use LiveData
If you want to modify your data later use MutableLiveData

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)