My Navigation graph has two destinations, a Fragment and a DialogFragment. The Fragment contains a Button that navigates to the DialogFragment when pressed.
Everything works as expected, except if I click the button very quickly. Doing so can trigger a
IllegalArgumentException: navigation destination com.example.app:id/show_dialog is unknown to this NavController
To fix this, I ensure that the current destination is the Fragment containing the show_dialog action:
val navController = findNavController()
val currentDest = navController.currentDestination?.id
if (currentDest == R.id.test_fragment) {
navController.navigate(TestFragmentDirections.showDialog())
}
Making this change appears to fix the issue. However, I would like to know:
Why is it necessary to wrap the
navigatecall with a conditional statement in this situation?