Y yhyzhj Member Oct 14, 2020 #1 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.
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 Oct 14, 2020 #2 You can not intercept HOME Key. Pressing home brings your app into background. This is how android works. Upvote 0
You can not intercept HOME Key. Pressing home brings your app into background. This is how android works.
agraham Expert Licensed User Longtime User Oct 14, 2020 #3 yhyzhj said: how to let the app keep running on background. Click to expand... Use B4XPages. Upvote 0
Y yhyzhj Member Oct 14, 2020 #4 i just want to write a app, let the volume+down key be invalid after open the app how to do? thanks Upvote 0
drgottjr Expert Licensed User Longtime User Oct 14, 2020 #5 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
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?
Y yhyzhj Member Oct 14, 2020 #6 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
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.
Erel B4X founder Staff member Licensed User Longtime User Oct 15, 2020 #7 You cannot intercept such keys when your app is in the background. Upvote 0