Android Question Handling delay in button click functionality.

Juzer Hussain

Active Member
Licensed User
Longtime User
Hi,

As I have observed user without waiting double clicks (or triple clicks) button if there is some delay in execution of the code.
Many a times it crashes app depending upon the code.
I would like to know best way to handle this.

1. Give Toast Msg to wait
2. Disable the button on click and enable later

Pls advice.

Thanks
Juzer
 

drgottjr

Expert
Licensed User
Longtime User
forget #1 (too slow, too late)
easy enough to try #2 ...
if you want to be "friendly", you could consider #3:
set a global flag on first click
on second (3rd, 4th clicks), sub checks flag
if flag is set, user sees message telling her to wait (then sub returns)
when job is done, you unset the global flag

with #2, you prevent crash, but user doesn't know what's going on and might just start clicking more to get some response from app.
also, in general, you don't want users tapping buttons at random or accidentally. unexpected stuff can happen. if button is clicked when it shouldn't be clicked, you should be ready to say something and take control.
 
Upvote 0

Juzer Hussain

Active Member
Licensed User
Longtime User
Thanks Drgottjr,
#3 is good but maintaining a global flag will have its own problem because if the flag is not reset (because of any reason net connection, coding error etc) the button in another form may not work. For this in all views form activate it will have to be reset first.
Juzer
 
Upvote 0

Juzer Hussain

Active Member
Licensed User
Longtime User
Hi Erel,

I wrote like

B4X:
Sub PP_Processing_Status () As Boolean
    If starter.bButtonClicked=True Then
        ToastMessageShow("Processing, Please Wait....",False)
        Return True
    Else
        starter.bButtonClicked=True
        Return False
    End If
End Sub

a function in class

In button click

If General.PP_Processing_Status=True Then Return

In every activate and after job finish resetting it to false

Is there any better method.

Juzer
 
Upvote 0

Juzer Hussain

Active Member
Licensed User
Longtime User
Thank You Erel,

This is what I was looking for although it is totally new thing for me.
It will make code much simpler.

Juzer
 
Upvote 0
Top