Deepak Goyal
1 min readFeb 12, 2018

--

This line is the key for the ViewModel MutableLiveData field. As you don’t have to add observer to each MutableLiveData field manually. This line handles the observers for you.

Suppose there is a field “name” in ViewModel and that field is updated from API response. As in the XML, I am using the value from the ViewModel to display the name. But as the “name” updates, the changes are not reflected in the UI But if I use MutableLiveData then I need to add observer in my Activity/Fragment and manually have to update the binding class. So I have used the “name” field as “ObservableField” which is updating my UI but obviously this field also tries to update the UI when activity is not in running state.

So this line will work in the above situation.

--

--

Deepak Goyal
Deepak Goyal

Written by Deepak Goyal

I’m a Software Engineer. I love programming. #java #android #kotlin #dart #flutter #firebase

Responses (1)