Migrating From LiveData to StateFlow

Federico Torres
The Startup
Published in
4 min readDec 9, 2020

--

I’ve worked a lot with LiveData and I think it is a great solution to save the UI state and observe it from the view layer without worrying about lifecycle issues, but…

What is wrong with LiveData?

This great data holder class in some cases is misused, in particular I have seen this two problems:

  • It is used everywhere, for example in the repository layer
  • Not knowing the difference between setValue() and postValue()

I don’t want to dive into the details of this two problems, a lot has been written about both of them, but to summarize: the first one will lead to performance issues and the second one might cause crashes and bugs in your app.

If you didn’t know this caveats of LiveData, here are some good articles talking about that.

--

--