Pick the fix
A detail ViewModel has fun init(id: String) called from the screen, and it reloads on every rotation. Best fix?
Hint 1 of 1
Where do navigation arguments already live?
Choose an answer, then open Show answer below to check it.
Show answer
Answer: A Read the id from SavedStateHandle in the ViewModel
Correct. The argument arrives with the ViewModel and is restored after process death.
Why not the others?
- B Guard init with a Boolean flag. Works for rotation, but not after process death, and it's easy to get wrong.
- C Call init in LaunchedEffect(Unit). Still runs again on rotation.
- D Make the ViewModel a singleton. Then all detail screens share one.