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 course, 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

Drag to resize

Maia Grotepass

Content Author & Course Instructor
About

I have been a mobile engineer since 2009. My first computer was a ZX81 and there was no Internet. Fast forward: I am still excited about learning and working with code, computers and people: building and exploring new things. I especially like to share my discoveries. For the past decade Android and its ever evolving framework, libraries and community have been my passion. I am an Android GDE and I love Kotlin. My dog is my best friend. I dance and do yoga to counter my sedentary lifestyle.