Check physical buttons of the device

consultatech4android

Member
Licensed User
Longtime User
Good morning to all of the forum.

Imagine the following situation:

I'm making a record or a turnover, and confirm the data before tightening the Boao "Exit" Application or "Back" button of your smartphone.

In the "Exit" button I can include a call to a routine to validate the output, but in the "Back" button Smartphone not know how to do this, since I do not have direct control over the events of the physical buttons of the device.

How do I do this?

:signOops:
 

anallie0

Active Member
Licensed User
Longtime User
B4X:
Sub Activity_KeyPress (KeyCode As Int) As Boolean 

If KeyCode = KeyCodes.KEYCODE_BACK Then 

'Perform your functions here
 
End If

 End Sub
:)
 
Upvote 0

consultatech4android

Member
Licensed User
Longtime User
Oh yes.

Thank you for the response. That was what I needed to solve the problem of leaving the activity without saving changes.

:sign0098:


:sign0060::sign0060::sign0060:
 
Upvote 0

anallie0

Active Member
Licensed User
Longtime User
with this you checks all events:
B4X:
Sub Activity_KeyPress (KeyCode As Int) As Boolean

    Select Case KeyCode
 
        Case KeyCodes.KEYCODE_MENU
            Return True             
           Case  KeyCodes.KEYCODE_DEL
            Return True           
           Case  KeyCodes.KEYCODE_DPAD_DOWN
            Return True           
           Case  KeyCodes.KEYCODE_DPAD_LEFT
            Return True           
           Case  KeyCodes.KEYCODE_DPAD_RIGHT
            Return True           
           Case  KeyCodes.KEYCODE_DPAD_UP
            Return True
        Case KeyCodes.KEYCODE_VOLUME_DOWN   
            Return True
        Case KeyCodes.KEYCODE_VOLUME_UP   
            Return True
           
           
           
        Case KeyCodes.KEYCODE_BACK
           
            'Your control
                Return True
            End If           

           
            Case Else
     
            Activity.finish

    End Select

End Sub
 
Upvote 0
Top