https://kotlinlang.org logo
#android-architecture
Title
# android-architecture
u

_shtomar

03/03/2022, 3:27 AM
What do you guys tends to use Flow or livedata?
g

gildor

03/03/2022, 7:36 AM
only Flow, removed all usages of livedata from the project, if we have any third party livedata API convert it to Flow to use it
u

_shtomar

03/03/2022, 9:56 AM
Thanks @gildor. I have in many blogs suggesting it. Is there any concrete reason to prefer flow over live data?
g

gildor

03/03/2022, 9:59 AM
Live data is extremely limited implementation of Observer pattern, it doesn’t allow you control threads, have very limite set of operators, doesn’t work natively with coroutines
Flow provides everything what LiveData + much more on top of it, supports nullability correctly and has better API
l

Landry Norris

03/03/2022, 1:44 PM
LiveData also makes future transitions to KMM more difficult if you ever decide to move to that. Flow is more flexible.
a

Alex Prince

03/03/2022, 3:21 PM
That's our major reason for preferring flow at this point is the flexibility, that code will run anywhere kotlin runs, livedata won't (of course, if you're in views or something, thats irrelevant)
c

Colton Idle

03/08/2022, 3:21 AM
I think the only reason to use LiveData is because it handles lifecycle out of the box, no?
but yeah. i pretty never use livedata.
g

gildor

03/08/2022, 3:23 AM
it handles lifecycle out of the box, no
Well depends what you mean by this. Flow also forces you think about lifecycle. The real difference is that LiveData stop collecting onStop and continues onStart, which is now possible to do with official extension for Flow (before you have to implement it yourself if you need such behaviour)
👍 2
3 Views