If I click multiple times on a button in a short time, sometimes the action gets executed multiple times (Depends on the click speed), is there a way to prevent this by using anything integrated into ButterKnife
?
After searching on google looking for a solution to that problem, I came through a SO post asking the same https://stackoverflow.com/a/38525054/7575454 after that, I tried digging a bit on the ButterKnife
source code and found the class named DebouncingOnClickListener
(Mostly looked on this class because the class "layout" was similar to a solution I found on StackOverflow).
There is a comment on that class that says
A click on one button disables all buttons for that frame
If I understand correctly, that means I shouldn't be able to "spam" click on my button. But it's not the case since I'm able to perform the action button multiple times if I spam click said button.
The solution I found on StackOverflow "fixes" my problem but I was just wondering if there was anything else similar to this on ButterKnife (Appart for the class that I said early) since I don't really want to do a mess on my source code setting the click listeners "manually" for a couple of buttons and use @OnClick
on the ones I don't really care if there are called multiple times.
The DebouncingOnClickListener
prevents multiple clicks in one frame. That's not a long delay, only a few milliseconds. As you can read as a comment to an issue, Jake Wharton (the author) considers this behavior as part of the application layer, which he doesn't want to add to Butter Knife.
It only debounces two clicks on one frame. If you click twice on two separate frames then that's the responsibility of the application layer to handle. You can fix this by disabling the button on the first click.
Or you have your application or domain implementing a time based debounce (depending on your use-case).