4

I have a host (activity) which contains 5 fragments and one of the fragment also acts like a host (nested graph) contains 2 fragments. I want to create a start destination dynamically in this host fragment.

I created the start destination dynamically in activity but can't create in fragment as it can't refer the id of nav host.

In activity I did this:

    val navHostFragment = nav_host_fragment as NavHostFragment
    val navController = navHostFragment.navController
    val navInflater = navController.navInflater
    val graph = navInflater.inflate(R.navigation.nav_main)
    graph.startDestination = R.id.detail_fragment
    val navShipmentId = NavArgument.Builder().setDefaultValue(shipmentId).build()
    navHostFragment.navController.graph = graph
Himanshu Arora
  • 309
  • 4
  • 13
  • Does this answer your question? [How to change start destination of a navigation graph programmatically \[Jetpack\]](https://stackoverflow.com/questions/51173002/how-to-change-start-destination-of-a-navigation-graph-programmatically-jetpack) – Maddy Mar 25 '20 at 06:41
  • Did you find any solution regarding this issue – Munir Sep 09 '20 at 06:53

0 Answers0