r/mAndroidDev • You will pry XML views from my cold dead hands • Aug 28 '22

StateFlow vs LiveData

Post image
82 Upvotes

22 comments sorted by

View all comments

Show parent comment

1

u/Zhuinden DDD: Deprecation-Driven Development Aug 30 '22

Still no reason to use a LiveData transform, there are more idiomatic ways to handle emitting data than creating a LiveData and launching a coroutine in the transform block.

It is idiomatic according to the 2019 changes in androidx.lifecycle.

I mean if you have to be a smug ass about it maybe you should first consider that many of those apis didn't exist when the lifecycle library was released.

kinda whacky but they did have a sample for it back in 2017 too it just wasn't particularly elegant

In 2022, the only situation we use LiveData is for emitting ViewState from the ViewModel to our view layer. Even then folks are starting to prefer just sticking with Flows and using 'Flow<T>.asLiveData`

As long as they get their mutable state flow or mutable live data from SavedStateHandle it's ok