I have 2 activities.
Main activity, let's call A has the navigation controller setup with Compose. The navigation controller works fine and it uses the same everywhere (No duplicated NavHostController)
I have a button on activity A that it launches the activity B. After finishing it returns and launches a lambda to call navController.navigate("foo").
It crashes with the following error:
java.lang.IllegalArgumentException: Cannot navigate to NavDeepLinkRequest{ uri=android-app://androidx.navigation/foo }. Navigation graph has not been set for NavController androidx.navigation.NavHostController@a2ff265.
The navigation controller works fine but when coming back from the activity B it creates a new navController object where the graph hasn't been setup, thus it crashes. I've checked this with the log.
To "solve" it I've done the following: Created a coroutineScope and then inside the scope navigated navController.navigate("somewhere") and it didn't crash. My feeling is that the issue could be related to the race condition.
Is there something that I could be missing? I know that when coming back from the activity the destination route are null. Maybe I'm doing something wrong.