Hi, I want to navigate to a new screen and clear t...
# compose
e
Hi, I want to navigate to a new screen and clear the back stack. Am I doing it in a right way? Code in 🧵
1
Copy code
NavHost(
    navController = navController,
    route = "nav_host",
    startDestination = startDestination
) {...}
and later
Copy code
navController.navigate(TargetScreen){
    popUpTo("nav_host")
}
i
You shouldn't be popping your start destination off the back stack at all as per the Principles of Navigation: https://developer.android.com/guide/navigation/navigation-principles#fixed_start_destination
Can you explain what you're trying to do?
e
@Ian Lake At the start destination, I'm checking the current user because the next screen depends on the user's role. I want to navigate to that start destination later only on <Logout> event.
i
That page also talks about how login should never be your start destination, a topic we've talked about here a number of times: https://kotlinlang.slack.com/archives/CJLTWPH7S/p1617812338353700?thread_ts=1617805109.343700&amp;cid=CJLTWPH7S
e
Login is not a start destination in the scheme
f
trying to get some clarity - why can't you navigate to the start destination while popping all other screens from the stack? Also, your screenshot reads "close app on backpress" - if you want to close the app, you can call
finish
on your activity