ViewModels with Saved State, Jetpack Navigation, Data Binding and Coroutines

Lyla Fujiwara
Jun 24 · 9 min read
Illustration by Virginia Poltrack

Saved State in ViewModels : ViewModel data that survives background process restart

The Challenge of onSaveInstanceState

Saved State Module

Setting up Saved State Module

implementation ‘androidx.lifecycle:lifecycle-viewmodel-savedstate:1.0.0-alpha01’

ViewModel and Jetpack Navigation : NavGraph with a ViewModel

The Challenge of ViewModel Sharing

Navigation Graph with some screens that are in a shopping checkout flow

ViewModel NavGraph Integration

Screenshot showing how to “Move to Nested Graph”

ViewModel and Data Binding : Use your ViewModel and LiveData in Data Binding

All that LiveData boilerplate

Using Data Binding, ViewModel and LiveData


ViewModel and Kotlin Coroutines : viewModelScope

Coroutines on Android

viewModelScope


Conclusion

Android Developers

The official Android Developers publication on Medium

Lyla Fujiwara

Written by

Android Developer Advocate @ Google

Android Developers

The official Android Developers publication on Medium