I would like to retrieve nested graph programmatically to change startDestination
.
that one works for navHost
val navHostFragment = appNavFragment as NavHostFragment
val inflater = navHostFragment.navController.navInflater
val graph = inflater.inflate(R.navigation.nav_app)
graph.startDestination = if(sth) startDestination1 else startDestination2
val navController = navHostFragment.navController
navController.graph = graph
And I would like to do the same for the nested graph, but I don't know how to retrieve it programmatically.
I found the solution, for a nested graph I needed to use findNode
val node = graph.findNode(R.id.nav_main)
(node as NavGraph).startDestination = R.id.onboarding_dest
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.