Better Programming

Advice for programmers.

Follow publication

Member-only story

Android Data Binding With MVVM: Using StateFlow and ViewModel

Siva Ganesh Kantamani
Better Programming
Published in
4 min readMar 24, 2021

View of Earth from space
Photo by NASA on Unsplash.

This is the third part of a series in which you’ll learn about Data Binding basics and how to use Data Binding with architecture components like LiveData and ViewModel. Today, you’ll learn how to use Kotlin coroutines and StateFlow to update the UI via Data Binding from a ViewModel.

Introduction

StateFlow

The Flow API in coroutines is a better way to handle a stream of data. StateFlow attempts to bring the powerful features of Flow to manage a state in your Android application.

As explained on GitHub, StateFlow comes in two variants: StateFlow and MutabaleStateFlow.

“The StateFlow<T> interface is a read-only view that gives access to the current value and implements a Flow<T> to collect updates to the values.

The…

Create an account to read the full story.

The author made this story available to Medium members only.
If you’re new to Medium, create a new account to read this story on us.

Or, continue in mobile web

Already have an account? Sign in

Write a response