RotateLab.kt
- 1class ReaderViewModel : ViewModel() {
- 2 var lessonId by mutableStateOf("nulls")
- 3 private set
- 4
- 5 fun open(id: String) {
- 6 lessonId = id
- 7 }
- 8}
Rotation keeps the lesson open
The composable is recreated. The ViewModel is not.
- State inside the composable, held only with remember, disappears when the activity is recreated.
- The open lesson id lives in the ViewModel.
- A SavedStateHandle is the next step when the process itself is killed. This lab names that limit.