Jetpack Compose navigate for result
Solution 1:
From the Composable that you want to return data, you can do the following:
navController.previousBackStackEntry
?.savedStateHandle
?.set("your_key", "your_value")
navController.popBackStack()
and then, from the source Composable, you can listen for changes using a LiveData
.
val secondScreenResult = navController.currentBackStackEntry
?.savedStateHandle
?.getLiveData<String>("your_key")?.observeAsState()
...
secondScreenResult?.value?.let {
// Read the result
}