IllegalArgumentException: navigation destination xxx is unknown to this NavController

后端 未结 30 2386
遇见更好的自我
遇见更好的自我 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:25

    Usually when this happens to me, I had the issue described by Charles Madere: Two navigation events triggered on the same ui, one changing the currentDestination and the other failing because the currentDestination is changed. This can happen if you double-tap, or click on two views with a click listener calling findNavController.navigate.

    So to resolve this you can either use if-checks, try-catch or if you are interested there is a findSafeNavController() which does this checks for you before navigating. It also has a lint-check to make sure you don't forget about this issue.

    GitHub

    Article detailing the issue

提交回复
热议问题