StateFlow with Jetpack Compose

Alternative of LiveData

Farhan Tanvir
2 min readMar 3, 2022
Photo by Tracy Adams on Unsplash

Recently I have heard that StateFlow will replace LiveData. StateFlow and LiveData have similarities and both are observable. Let’s know about it more.

What is StateFlow

According to official documentation

StateFlow is a state-holder observable flow that emits the current and new state updates to its collectors. The current state value can also be read through its value property. To update state and send it to the flow, assign a new value to the value property of the MutableStateFlow class.

We will learn it with a basic example.

What are we Reading

It’s a great app. Isn’t it? 😉

Let’s Start

First, create a ViewModel.

--

--

Farhan Tanvir

Believes in learn by doing . Currently working as a software engineer. Love to share Knowledge. https://twitter.com/FarhanTanvirBD