Christophe Beyls
1 min readFeb 15, 2024

--

LiveData is OK and not deprecated and you can keep using it. But it only supports a very limited set of operators compared to Kotlin Flow. It's not meant to replace RxJava or Flow for all scenarios.

You can use the LiveData coroutine builder or flow.asLiveData() to bridge the gap between coroutines and LiveData, but be aware that the coroutine that runs underneath such a LiveData instance will be subject to the same limitation: it will restart from scratch after the LiveData instance becomes inactive.

If you want true lifecycle awareness across the chain, either you only use LiveData and its operators (map, switchMap, distinctUntilChanged) for all your transformations or you use Flow with the techniques described in this article.

Finally, LiveData is tied to Android and its Lifecycle class. You may want to move to cross-plaform ViewModel implementations at some point and you can do that using Flow, but not LiveData.

--

--

Christophe Beyls
Christophe Beyls

Written by Christophe Beyls

Android developer from Belgium, blogging about advanced programming topics.

No responses yet