I am using Room for my Database management and I was confused in what to use while working with real-time data. For now, to manage real-time data I am using Flowable
and am I pretty satisfied with it. What I was confused is I can use LiveData
as well to do the same operation.
To give some context, here is how I am querying data and updating my view.
Flowable
addDisposable(userDao().getUsersFlowable()
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(users -> userAdapter.setUsers(users)));
LiveData
userDao().getUsersLiveData()
.observe(this, users -> {
userAdapter.setUsers(users)
})
I am not much familiar with LiveData
, but as far as my research goes it is an observer pattern that is also lifecycle aware, meaning that I will stop notifying if UI is not in active state. That said, as you can see in my Flowable
code, I am adding it to CompositeDisposable
and I will dispose in my onDestroy()
method.
So I don't see point of why I should use LiveData
when I can manage everything with RxJava
, which has a lot of operators for convenience.
So when should I use LiveData
and when RxJava
while working with Room. Answers reflecting given scenario is much appreciated, but other use cases are also welcomed.
I followed When to use RxJava in Android and when to use LiveData from Android Architectural Components?, but it's too broad and I couldn't get answer specifically in my case