After reading <this thread> it seems like using An...
# compose
m
After reading this thread it seems like using Android's `LiveData`has no benefits over using standard Compose's `State`or coroutines'
Flow
. Yet, official jetpack compose codelab does use it quite extensively (although switches out of it at the end). If the first line is true, I think this guide should not suggest it at all, maybe just mention it as a possibility. Even if `LiveData`is as OK as the former options it introduces unnecessary complexity and decision-branches.
t
Compose doesn't really care where your data comes from. The advantage of LiveData is that it's automatically lifecycle-aware, so you don't have to deal with LifecycleCoroutineScope or otherwise deal with receiving events while your app is stopped. The disadvantage is that it ties your data model to Android, and conversion to Flow/State is not free (but is likely negligible).
👍🏻 1
i
Yep, keep in mind that
Flow.collectAsState()
will continue to collect even after you hit the home button and you're back on the launcher (as your activity is stopped, but not destroyed - thus your UI is not disposed). You'd need to use
flowWithLifecycle
if you want it to stop collecting once your activity is no longer visible: https://medium.com/androiddevelopers/a-safer-way-to-collect-flows-from-android-uis-23080b1f8bda#27a9
👍🏻 1
That's something you get for free with
LiveData
, FWIW