0
I have a delivery app, where when clicking the button a request is triggered, it turns out that there is a bug that even with a preventive code to enter, sometimes it happens that in thousandths of seconds two or more orders are triggered at the same time, in the case when clicking the button that triggers, I believe that this is occurring due to more than a click by the user on the button (although it would have to be very fast, because soon after appears a dialog).
I was trying to make it not happen by putting the following code right after the button is clicked:
//prevent two click the same time
if (SystemClock.elapsedRealtime() - mLastClickTime < 30000) {
Toast.makeText(getBaseContext(),"Aguarde 30 segundos para solicitar uma nova corrida",Toast.LENGTH_LONG).show();
return;
}
mLastClickTime = SystemClock.elapsedRealtime();
Already tried to disable the button after the first click?
– viana
The button has to be active again after 30 seconds for example...
– Mateus Carvalho
Use
myButton.setEnabled(false);
ai after 30 seconds you enable again.– viana
I’m wondering if the dialog that exists to confirm that you’re causing this... The process is: clicked on the button, shows a dialog asking if it confirms the request, if it clicks yes again there it fires... @acklay
– Mateus Carvalho
This is a type of problem that Functional Reactive solves very well. You would make a mapSwitch in the click event with a debouce, and the problem is over. This question of double-clicking (or n clicks) with request to the server, even using prefixes or deferreds, are almost impossible to actually resolve with vanilla js. Take a look at lib Rx. Who knows you don’t adopt in the project. Oh, and that without changing the state of the button. Better yet, without maintaining any state! : ) Abc
– Igor Donin