Yousuf Sohail
Yousuf Sohail

Reputation: 603

What is the difference between Android MutableLiveData vs ObservableList?

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

Answers (1)

Demigod
Demigod

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

Related Questions