Hi all, i have a composable `composable("profile/{...
# compose
b
Hi all, i have a composable
composable("profile/{userId}"){}
how to get the
startDestination
to be something like
NavHost(startDestination = "profile/42") {}
instead of having to navigate like
navController.navigate("profile/42")
i
First of all, it is extremely rare that you'd want that as your start destination and is indicative of the potential of a much bigger issue with how you've decided to structure your app
But to answer your question: set the
defaultValue
of your argument to 42: https://issuetracker.google.com/issues/191214681#comment3
1
b
i have my default startDestination, however there is a specific situation where i would want to go to a specific page at start with some arguments
i
No, you really should never be doing that; that isn't the right way to solve any use case. Could you elaborate on what you are trying to do?
1
c
@brabo-hi your start destination should always be the same destination (optimize for the typical use case. Example: do you have an app that requires a user to login first? You should still start at the HomeScreen and in that screen check if the user is logged in. If not, navigate them out to the login screen) I've seen some people here (and even on a popular live stream on twitch) where people are putting a conditional around their nav host. You should definitely not do that. Like Ian said though, seems like an xyproblem.info can you share your use case?
b
sure, i have the normal splashscreen -> check login flow. I also have a detail screen that starts a foreground service like a music player. Whenever user closes the (app)screen he should be able to get back to the detail screen whenever he clicks on the notification.
i
You don't change your start destination for notifications, see the docs on deep linking, which specifically talks about how to tie your notification to start a particular destination: https://developer.android.com/jetpack/compose/navigation#deeplinks
1
c
also for splash screen, make sure you're not setting up some kind of splash screen destination. generally, a forced splash screen is an anti pattern and the android docs recently added more guidance and an androidx lib for splashscreens. https://developer.android.com/guide/topics/ui/splash-screen
1