Navigating To DialogFragment Produces IllegalArgumentException If Button Pressed Quickly?
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
navigate
call with a conditional statement in this situation?
Answer
Your question is just based on the Android inside Architecture and is also dependent on the hardware performance. Just wrap it in a try/catch
block:
try{
findNavController().navigate(TestFragmentDirections.showDialog())
}catch(e: IllegalArgumentException){
e.printStackTrace
}
Related Questions
- → should I choose reactjs+f7 or f7+vue.js?
- → Phonegap Android write to sd card
- → Local reference jquery script in nanohttpd (Android)
- → Click to navigate on mobile devices
- → How to allow api access to android or ios app only(laravel)?
- → Access the Camera and CameraRoll on Android using React Native?
- → React native change listening port
- → What is the default unit of style in React Native?
- → Google play market autocomplete icon
- → Warning: Each child in an array or iterator should have a unique "key" prop. Check the render method of `ListView`
- → Using Laravel with Genymotion
- → react native using like web-based ajax function
- → react native pdf View