Issue
I'm using JetPack Compose with composable NavHost.
I have a scenario where I need a Launch screen that connects bluetooth device so I've set it as my starting route in NavHost.
After connection is done I want to enter Home screen and never get back to that Launch screen.
So after connection is done Launch screen I'm doing this:
navController.graph.setStartDestination(newHomeRoute)
navController.navigate(newHomeRoute) {
popUpTo(0)
launchSingleTop = true
}
That doesn't work as I get a constant loop going back to LaunchScreen and forward to Home.
So maybe I should do this in some other way?
Solution
I managed to do this with extension like this:
fun NavHostController.navigateAndReplaceStartRoute(newHomeRoute: String) {
popBackStack(graph.startDestinationId, true)
graph.setStartDestination(newHomeRoute)
navigate(newHomeRoute)
}
Answered By - miszmaniac
Answer Checked By - Willingham (JavaFixing Volunteer)