Navigation Architecture Component- Passing argument data to the startDestination

前端 未结 9 783
情话喂你
情话喂你 2020-12-05 16:43

I have an activity A that start activity B passing to it some intent data. Activity B host a navigation graph from the new Navigation Architecture Component.I want to pass t

9条回答
  •  南方客
    南方客 (楼主)
    2020-12-05 17:41

    addDefaultArguments is no more in the latest versions of library. I have fixed the problem like this:

            val navHostFragment = fragment_navigation_onboarding as NavHostFragment
            val navController = navHostFragment.navController
            val navInflater = navController.navInflater
            val graph:NavGraph = navInflater.inflate(R.navigation.navigation_your_xml)
            val model = Model()//you might get it from another activity
            graph.addArgument("Data", NavArgument.Builder().setDefaultValue(model).build()) // This is where you pass the bundle data from Activity to StartDestination
            navHostFragment.navController.graph = graph
    

提交回复
热议问题