A small status panel should show the last loading result and update correctly after returning to the screen. After process recreation and when the configuration changes, the state should also be restored predictably.
Requirements
- The screen uses
StatusViewModel, StateFlow, and SavedStateHandle.
- During loading, the UI must show
Loading, then either Success or Error.
- If the user leaves the page and then returns, the previous loading should not keep changing an already closed screen.
- After a configuration change or process recreation, the last known status must be restored from
SavedStateHandle.
- Only Android API 35, Kotlin 2.0, and
kotlinx.coroutines 1.8.1 are supported.
- The code builds in a regular Android app module without extra libraries, except those specified in the files below.
- Assumptions:
ViewModel lives in activity scope, state collection happens in the UI layer, and loading starts from init.
Reproduction
- Open the status screen.
- Wait for loading to start and immediately navigate back.
- Return to the screen before the first loading finishes.
- Observe that the old response either overwrites the new state, or after process recreation the screen remains without a restored status.
Expected behavior
- Each new visit to the screen must have an independent loading operation.
- An outdated result must not reach the current state after leaving the page.
- The last valid state must survive screen rotation and process restoration.