Android Question a question about intercept key

yhyzhj

Member
I want to intercept a key. eg:volume_up
I use these code, it work. but if press home or back, the app will exit. it cant work.
B4X:
Sub Activity_keyPress (KeyCode As Int) As Boolean 'Return True to consume the event
     If KeyCode = KeyCodes.KEYCODE_VOLUME_UP Then
        ToastMessageShow("up",False)
        Return True
    End If
End Sub
how to let the app keep running on background.
 

DonManfred

Expert
Licensed User
Longtime User
You can not intercept HOME Key. Pressing home brings your app into background. This is how android works.
 
Upvote 0

drgottjr

Expert
Licensed User
Longtime User
you already did it (your code from first post):
B4X:
Sub Activity_keyPress (KeyCode As Int) As Boolean 'Return True to consume the event
     If KeyCode = KeyCodes.KEYCODE_VOLUME_UP Then
        ToastMessageShow("up",False)
        Return True
    End If
End Sub

just add a test for KeyCodes.KEYCODE_VOLUME_DOWN.
this has nothing to do with back or home keys. what's the problem?
 
Upvote 0

yhyzhj

Member
yes,i know it can work. but cant keep working when press a back key or home key. i need it work on background.when i browse web or do other thing, it still can work.
 
Upvote 0
Top