StateFlow

what is Stateflow?

StateFlow is an interface, which contains read-only and always return the updated value.The update value is passed through implemented flow like MutableStateFlow.

StateFlow return only when the value is updated if same value mean it doesnt return

StateFlow is observed using collect inside corroutine scope like below

where countState is a StateFlow variable inside viewmodel

where collect is a suspend inline function so only we are calling inside coroutine scope

Sample Example below

ViewModel class

Followed by layout class

Knowledge is everything.Check out my app at https://play.google.com/store/apps/details?id=com.vibe.britevibe

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Introduction To MotionLayout In Android

Flutter Task 1

Is Flutter the future of App Development?

OpenMRS Android Client

Convert JSON to Data Classes Using a Nice Android Studio Plugin

Android Studio Design Tools UX Changes — Split View

Implement Android RecyclerView list of checkboxes with “select all” option — double tier!

Episode 2:Setting up the development Environment for Jetpack Compose

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Pandiyan Mani

Pandiyan Mani

Knowledge is everything.Check out my app at https://play.google.com/store/apps/details?id=com.vibe.britevibe

More from Medium

Scope functions in Kotlin

DataBindingUtil.inflate vs View Binding Inflate

How to ask runtime camera permission after denied in android kotlin

Android camera permission

Android View Binding Without Boilerplate  —  Part 1