Navigation Architecture Component- Passing argument data to the startDestination

前端 未结 9 784
情话喂你
情话喂你 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:42

    OK, I found a solution to that problem thanks to Ian Lake from the Google team. Let say you have an activity A that will start activity B with some intent data and you want to get that data in the startDestination you have two options here if you using safe args which is my case you could do

    StartFragmentArgs.fromBundle(requireActivity().intent?.extras)

    to read the args from the Intent. If you don't use safe args you can extract the data from the bundle your self-using requireActivity().intent?.extras which will return a Bundle you can use instead of the fragment getArguments() method. That's it I try it and everything works fine.

提交回复
热议问题