Android Jetpack - Navigation 组件踩坑日记

Author Avatar
Omico Yuwen 11月 21, 2019
  • 在其它设备中阅读本文章

java.lang.IllegalArgumentException: navigation destination NAVAGATION_ACTION_ID is unknown to this NavController

当我发呆时,无意用手指同时点击了2个包含 Navigation 跳转的 Item,触发了这个问题。

修复前

1
Navigation.findNavController(view).navigate(NAVAGATION_ACTION_ID);

修复后

1
2
3
4
NavController navController = Navigation.findNavController(view);
NavDestination currentDestination = navController.getCurrentDestination();
if (currentDestination != null && currentDestination.getId() == CURRENT_ID)
navController.navigate(NAVAGATION_ACTION_ID);

This blog is under a CC BY-NC-SA 3.0 CN License
本文链接:https://blog.omico.me/android-jetpack-navgation-notes/