sunflower: Navigation component crashes.

I guess this is just broken Navigation, and i’m going to post this issue at Navigation bug tracker but still.

  1. Open Plant list screen
  2. With 2 or more fingers tap different Plant items at the same time
  3. You will get exception

java.lang.IllegalArgumentException: navigation destination com.google.samples.apps.sunflower:id/action_plant_list_fragment_to_plant_detail_fragment is unknown to this NavController

Seems like after first click Navigation framework thinks you are already at Plant detail part of the nav graph. And this fragment can’t use this action. It seems just broken as for me. I’d like it opens two separate screens if you do things like this. This probably will crash you app everywhere when you can navigate with more then 1 then click listener (for example 2 buttons to register/forgot password screens)

In the current situation i have found few workarounds with this problem:

  1. We can wrap it.findNavController().navigate(direction) with tryCatch block, catch IllegalArgumentException and do nothing. But it seems just broken, don’t forget to leave a commentary in that catch block
  2. You can use Global actions only https://developer.android.com/topic/libraries/architecture/navigation/navigation-global-action But this is again will look just horrible tho. This seems acceptable if we add search into the app
  3. You can add to PlantDetailFragment in nav graph action to navigate to itself (recursive). This is horrible as well.

Offtopic: if you use recursive destination and tie ActonBar with NavController - check you home/back button. This will be broken if your recursive destination is first in nav graph.

Well, i don’t have the good looking solution for the issue quite yet. Still working

UPD: Copy of this bug at google tracker https://issuetracker.google.com/issues/118975714

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 3
  • Comments: 16 (7 by maintainers)

Commits related to this issue

Most upvoted comments

@opengamer29 you could try a different navigation library that can also make navigation from one screen to another an actual one-liner, and wouldn’t crash from tapping two plants at once

See https://github.com/Zhuinden/simple-stack-tutorials/blob/534a2c63a6827bbfd3179ac2d2dd75d863dd843e/app/src/main/java/com/zhuinden/simplestacktutorials/steps/step_5/Step5FirstFragment.kt#L19

Thanks a lot man, You just saved my day.

@opengamer29 you could try a different navigation library that can also make navigation from one screen to another an actual one-liner, and wouldn’t crash from tapping two plants at once

See https://github.com/Zhuinden/simple-stack-tutorials/blob/534a2c63a6827bbfd3179ac2d2dd75d863dd843e/app/src/main/java/com/zhuinden/simplestacktutorials/steps/step_5/Step5FirstFragment.kt#L19 😏

@KoTius thanks for reporting this issue. I can reproduce it even with with the changes in #238. It’s a good idea to create a bug in the navigation tracker, too.