IllegalArgumentException: navigation destination xxx is unknown to this NavController

后端 未结 30 2399
遇见更好的自我
遇见更好的自我 2020-11-27 11:28

I am having issue with the new Android Navigation Architecture component when I try to navigate from one Fragment to another, I get this weird error:

30条回答
  •  我在风中等你
    2020-11-27 12:08

    What I did to prevent the crash is the following:

    I have a BaseFragment, in there I've added this fun to ensure that the destination is known by the currentDestination:

    fun navigate(destination: NavDirections) = with(findNavController()) {
        currentDestination?.getAction(destination.actionId)
            ?.let { navigate(destination) }
    }
    

    Worth noting that I'm using the SafeArgs plugin.

提交回复
热议问题