Migrating LiveData to Kotlin Flow with Tests in Android

LiveData has been dominating Android apps for quite a while. But with the introduction of Jetpack Compose and Coroutines, Kotlin Flows have been embraced by Android developers for building applications. Explore how to migrate from LiveData to Kotlin Flow while writing appropriate unit tests by using a sample app that fetches a random password from the internet and displays it to the user.

In this coffee break codelab, you'll explore:
  • Overview of Flow and StateFlow 
  • LiveData vs. Kotlin Flows  
  • When to use Flow and StateFlow? 
  • Convert LiveData to a Flow within the Repository layer 
  • Write a unit test to test a Flow in the Repository layer 
  • Convert LiveData to a StateFlow within the ViewModel  
  • Write a unit test to test a StateFlow in the ViewModel 
  • Consume a StateFlow in Jetpack Compose in a lifecycle-safe way 

Meet the instructor

Maia Grotepass

Content Author & Course Instructor

More courses by the instructor

\Learnworlds\Codeneurons\Pages\ZoneRenderers\CourseCards