A small confirmation screen in a Fragment must return a one-time result to the previous screen and survive recreation correctly after rotation.
Requirements
- The confirmation screen opens as a separate
Fragment and, after the Confirm action, must close via NavController.popBackStack().
- The previous screen reads the result from
savedStateHandle and shows a status string.
- The result must be delivered exactly once per confirmation.
- After process recreation or screen rotation, a new instance must not resend an already handled result.
- The implementation works on Android API 35, Kotlin 2.0,
androidx.fragment:fragment-ktx:1.8.5, androidx.lifecycle:lifecycle-viewmodel-ktx:2.8.4, androidx.navigation:navigation-fragment-ktx:2.7.7, kotlinx.coroutines:1.8.1.
- Assumptions: the build runs in a normal app process, without Hilt/Compose, navigation is performed through the fragment
NavController, and configuration changes may happen at any time.
Reproduction
- Open the confirmation screen from the list.
- Tap
Confirm.
- Return to the previous screen.
- Rotate the device or recreate the fragment.
- Repeat confirmation again.
Expected behavior
- After the first confirmation, the previous screen receives one result and updates the status text.
- After returning, the result does not remain in
savedStateHandle as an active event.
- When reopened and confirmed again, only the new result is delivered, without the old one firing again.