Reputation: 603
I want to understand the difference between MutableLiveData vs ObservableList in Android ViewModel.
val questions: MutableLiveData<List<Question>> = MutableLiveData()
val options: ObservableList<Option> = ObservableArrayList()
Upvotes: 3
Views: 2727
Reputation: 5635
The main difference here is that ObservableList
is designed for DataBinding
while MutableLiveData
for data change observation that is made from Activity
or Fragment
, which means that MutableLiveData
takes into consideration a LifeCycle
of a component and will not call it if isn't in active state.
You can use ObservableList
from your code of course, but, for example, it will not hold last passed data, unlike LiveData
.
Upvotes: 2