Android Question b4a button down-up event bounce

mdehrnsb

Member
Licensed User
Longtime User
I have an application where I need to hold a button down to keep a relay activated on an embedded device using BLE but I am experiencing Done/Up event bouncing. I have read several other threads relating to this issue. I have tried a number of devices from small phones to tablets and it appears more prevalent as the device gets larger in size.

I really need to find a solution for this problem. I have tried to use a panel instead of a button and use the Touch event but it is not any better as to the event bouncing. Is this an issue with b4a or android? I have read some discussion relating to the use of the reflection class but I have no experience with it. If anyone can give me a concrete example of a proven solution, I would greatly appreciate it.
 

mdehrnsb

Member
Licensed User
Longtime User
I have the code at home and I can upload tonight but basically I have created a Touch event for the panel and have code similar to this:

I have defined a panel in the layout and created a reference in the global section: private Panel1 as Panel.

In the Touch event handler, the code is similar to below:

sub Panel1_Touch (Action As Int, X As Float, Y As Float)

if Action = Panel1.ACTION_DOWN then
log("Panel down")

else if Action = Panel1.ACTION_UP then
log("Panel up")

end if
end sub

I have tried this on various hardware platforms with similar results. In most cases, I get "Panel down" followed by "Panel up" events even though I have not taken my finger off the panel. I originally coded with Buttons using the Up and Down events and had similar results. I have tried this same exact code on various platforms from a ~4 inch phone to 8 inch tablets. It seems that the larger the device, the the higher the potential of this occurring. I have used the button code on my 5 inch Motorola MAXX and a 4.5 inch Galaxy Core Prime with reasonable results, but the exact same apk file on larger devices cause event bouncing.

It seems that this issue has been intermittent from device to device for many years, based on the forum. Unfortunately, I really need this operation to work across hardware platforms and right now, the button up/down events are fairly useless in their current operating state.

Any assistance on your part would be greatly appreciated...

Thank you.

Mark
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Please use [code]code here...[/code] tags when posting code.

I've tested this code on several devices and it worked properly:
B4X:
Sub Globals
   Private Panel1 As Panel
End Sub

Sub Activity_Create(FirstTime As Boolean)
   Activity.LoadLayout("1")
End Sub

Sub Panel1_Touch (Action As Int, X As Float, Y As Float)
   If Action = Panel1.ACTION_DOWN Then
     Log("Panel down")
   else if Action = Panel1.ACTION_UP Then
     Log("Panel up")
   End If
End Sub
There were no bounces.

The touch events are raised from the system. If you do see bounces then this means that the system detected those changes, even if they didn't happen.

You can use CallSubPlus to run a sub 50ms after the ACTION_UP event. In this sub check the current touch state (store it in a global variable). This will allow you to ignore bounces.
 
Upvote 0

mdehrnsb

Member
Licensed User
Longtime User
I will try your suggestion. I am assuming that the state stored in the global variable is from the initial ACTION_DOWN event? Is there any other way to read the current touch state other than by an event?
 
Upvote 0

gz7tnn

Member
Licensed User
Longtime User
I have been able replicate both what you want and also what you are experiencing.
What I notice is:
If I put my finger on the button and move it even slightly, the down and up event gets triggered.
But if I firmly touch the button with no movement, the the state does not change..
Would indicate to me that I is 'how' you touch the button or panel that controls the result
 
Upvote 0

Widget

Well-Known Member
Licensed User
Longtime User
One workaround would be to start a timer on the Button1_ActionUp event and if the Button1_ActionDown event gets fired again within say 250ms the timer is disabled (not allowed to fire). The timer will hold the code that would normally be in the Button1_ActionUp event. This should work until Erel can come up with a solution in an update.
 
Upvote 0
Top