Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Livedata vs Rxjava

I have to spend a lot of time learning and implementing Livedata (especially MediatorLivedata) in business logic because it helps to add data from various sources. Had a success with it, because I could add FCM, Network or RoomDatabase as different sources to my MediatorLivedata and observe it in ViewModel. Its actually scales very well. However, it still lacks powerful RxJava2 implementation, like chaining requests well, flat map and etc. It seems that RxJava is used primarily in Business logic, but in fact, I saw a lot of companies using RxJava with UI with additional features/libraries. This actually makes LiveData irrelevant in presentation logic. So I would like to know if LiveData is somehow better/cleaner in presentation logic(using it in a ViewModel) vs RxJava. What would you suggest looking into the future?

like image 688
Viktor Vostrikov Avatar asked Aug 03 '18 04:08

Viktor Vostrikov


1 Answers

RxJava is neither better nor worse to LiveData, it is different. Android Architecture Components was designed to give a model architectural pattern to android developers. So, if you're comfortable with LiveData, use that, or if you're comfortable with RxJava, use that. You can do all operations using both libraries. Though RxJava do contain a lot of syntactic sugar, same can be achieved using Livedata also.

like image 164
f0f1 Avatar answered Oct 21 '22 04:10

f0f1