The recipient selection screen stores a list of recipients and allows multiple items to be selected before confirmation. After a recent change, problems appeared that show up only when data is refreshed and the Activity is recreated.
SavedStateHandle.confirmSelection() must confirm exactly the currently selected items.confirmedNames state must contain the names of the confirmed recipients in the current order of selection from the current list.RecipientPickerViewModel with SavedStateHandle and RecipientRepository.u1 and u3 through toggleRecipient(...).replaceRecipients(...) with the same identifiers, but in a different order.confirmSelection() and check the contents of confirmedNames.RecipientPickerViewModel with the same SavedStateHandle and make sure the restored selection matches the same recipients.Example data for step 3:
listOf(
Recipient("u3", "Cara"),
Recipient("u1", "Ava"),
Recipient("u2", "Ben")
)
id.ViewModel recreation, the selection is restored for the same recipients by id.confirmSelection() publishes the names of the currently selected recipients, not the items by outdated indexes.androidx.lifecycle:lifecycle-viewmodel-savedstate:2.8.4org.jetbrains.kotlinx:kotlinx-coroutines-core:1.8.1SavedStateHandle survives ViewModel recreation and returns previously written valuesloadRecipients() returns the current snapshot of the list, saveConfirmed(names) saves the final names in the order passed by the callerUse line comments to explain the problem, its impact, the fix and how to test it.