https://kotlinlang.org logo
Title
e

emmano

04/21/2020, 1:20 PM
Quick question, if you are using Android’s Navigation component, how are you making sure button clicks are debounced so you do not get this type of
Exception
?
java.lang.IllegalArgumentException navigation destination action_loadingFragment_to_fragmentHome is unknown to this NavController
w

wasyl

04/21/2020, 1:42 PM
There’s some discussion about this on the r/androiddev subreddit: https://www.reddit.com/r/androiddev/comments/g4utqz/what_missing_features_prevents_you_from_using/
In our app we check whether we’re on the destination that we expect before navigating. That is for a button click, we only navigate if current navigation id == id for screen on which the button is placed
d

dewildte

04/21/2020, 3:54 PM
I tie the button click to a Command. The button's
isEnabled
is always equal to the Command's
isExecutable
boolean. When the command is invoked it changes
isExecutable
to false while it is running. This in turn is observed by the Button and the button will disable itself while the command is running. Also the Command can be asked if a navigation is possible by the
NavigationCommand#canExecute(R.id.someNavigationActionId)
function.
👌 2
No need for debouncing.