architecture-samples
architecture-samples copied to clipboard
[main] User input for add/edit screen is lost across process death
Similarly to older issues that have since been either closed or fixed such as https://github.com/android/architecture-samples/issues/370 and https://github.com/android/architecture-samples/issues/123 and https://github.com/android/architecture-samples/issues/731 and https://github.com/android/architecture-samples/issues/663
This bug seems to have been long-standing, but with MutableStateFlow(UiState)
it still persists - as on this screen, SavedStateHandle is used only for transferring screen arguments to the ViewModel, but is not actually used to preserve user inputs across process death.
https://github.com/android/architecture-samples/blob/7e9d96d808a0d25a689d14099ecf0eb3ea7d5b1f/app/src/main/java/com/example/android/architecture/blueprints/todoapp/addedittask/AddEditTaskViewModel.kt#L39-L40
On the other hand, TasksViewModel correctly persists the current filter state using savedStateHandle.getStateFlow
.
https://github.com/android/architecture-samples/blob/7e9d96d808a0d25a689d14099ecf0eb3ea7d5b1f/app/src/main/java/com/example/android/architecture/blueprints/todoapp/tasks/TasksViewModel.kt#L64-L65
Filtering state on the tasks screen was originally fixed by setting it on the SavedStateHandle in this commit: https://github.com/android/architecture-samples/commit/cfb5ac6ea6a5c888b171d88d7ea4287a33af5cb9#diff-631edb6efa01767b52856a0e498dc3987e8a2f0e8ba02837377dfbc5684af0cfR111
Therefore, AddEdit screen should also correctly save/restore user inputs across process death.