What do you guys tends to use Flow or livedata?
# android-architecture
u
What do you guys tends to use Flow or livedata?
g
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
Thanks @gildor. I have in many blogs suggesting it. Is there any concrete reason to prefer flow over live data?
g
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
LiveData also makes future transitions to KMM more difficult if you ever decide to move to that. Flow is more flexible.
a
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
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
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