epiCode Active Member Licensed User Mar 11, 2022 #1 In my original project which did not use B4XPages I was able to trap back key by following code in Main Activity Objective here is trap back key and close drawer if open else ask if user wants to exit without saving Code: Copy Sub Activity_KeyPress (KeyCode As Int) As Boolean Select KeyCode Case KeyCodes.KEYCODE_BACK 'close left drawer if open If Drawer.LeftOpen Then Drawer.LeftOpen = False Return True End If '''code to confirm exit Activity.Finish End Sub After moving the project to B4XPages it is structured like this Code: Copy Sub Activity_KeyPress (KeyCode As Int) As Boolean 'Return True to consume the event B4XPages.GetManager.RaiseEvent(B4XPages.GetManager.GetTopPage, "B4XPage_KeyPress", Array(KeyCode)) Return False End Sub Code: Copy Sub B4XPage_KeyPress(KeyCode As Int) As Boolean .... same code as above ..... End Sub Now when the back key is pressed, the code still gets triggered but application is minimized/paused first and results in following error Code: Copy ** Activity (main) Resume ** <--- ((back key pressed)) ** Activity (main) Pause event (activity is not paused). ** Error occurred on line: 1711 (B4XEdViewer) android.view.WindowManager$BadTokenException: Unable to add window -- token android.os.BinderProxy@2b8ac14 is not valid; is your activity running? Last edited: Mar 13, 2022
In my original project which did not use B4XPages I was able to trap back key by following code in Main Activity Objective here is trap back key and close drawer if open else ask if user wants to exit without saving Code: Copy Sub Activity_KeyPress (KeyCode As Int) As Boolean Select KeyCode Case KeyCodes.KEYCODE_BACK 'close left drawer if open If Drawer.LeftOpen Then Drawer.LeftOpen = False Return True End If '''code to confirm exit Activity.Finish End Sub After moving the project to B4XPages it is structured like this Code: Copy Sub Activity_KeyPress (KeyCode As Int) As Boolean 'Return True to consume the event B4XPages.GetManager.RaiseEvent(B4XPages.GetManager.GetTopPage, "B4XPage_KeyPress", Array(KeyCode)) Return False End Sub Code: Copy Sub B4XPage_KeyPress(KeyCode As Int) As Boolean .... same code as above ..... End Sub Now when the back key is pressed, the code still gets triggered but application is minimized/paused first and results in following error Code: Copy ** Activity (main) Resume ** <--- ((back key pressed)) ** Activity (main) Pause event (activity is not paused). ** Error occurred on line: 1711 (B4XEdViewer) android.view.WindowManager$BadTokenException: Unable to add window -- token android.os.BinderProxy@2b8ac14 is not valid; is your activity running?
Erel B4X founder Staff member Licensed User Longtime User Mar 13, 2022 #2 Code with Msgbox = broken code. Better not to post it in the forum. The example handles the back key and closes the drawer: https://www.b4x.com/android/forum/threads/b4x-b4xpages-b4xdrawer.120246/#content Upvote 0
Code with Msgbox = broken code. Better not to post it in the forum. The example handles the back key and closes the drawer: https://www.b4x.com/android/forum/threads/b4x-b4xpages-b4xdrawer.120246/#content
epiCode Active Member Licensed User Mar 13, 2022 #3 Erel said: Code with Msgbox = broken code. Better not to post it in the forum. The example handles the back key and closes the drawer: https://www.b4x.com/android/forum/threads/b4x-b4xpages-b4xdrawer.120246/#content Click to expand... 1. Removed Msgbox Code from example. 2. Using the code in example - My B4XPage_Keypress does not trigger - While it does trigger B4XPage_CloseRequest it gives me no 'Keycode" and no other alternate to intercept other keys like volume / play / pause. I appreciate your help. Upvote 0
Erel said: Code with Msgbox = broken code. Better not to post it in the forum. The example handles the back key and closes the drawer: https://www.b4x.com/android/forum/threads/b4x-b4xpages-b4xdrawer.120246/#content Click to expand... 1. Removed Msgbox Code from example. 2. Using the code in example - My B4XPage_Keypress does not trigger - While it does trigger B4XPage_CloseRequest it gives me no 'Keycode" and no other alternate to intercept other keys like volume / play / pause. I appreciate your help.
Erel B4X founder Staff member Licensed User Longtime User Mar 13, 2022 #4 mohsyn said: Objective here is trap back key and close drawer if open else ask if user wants to exit without saving Click to expand... If this is the objective then the solution is here: https://www.b4x.com/android/forum/threads/b4x-b4xpages-b4xdrawer.120246/#content If you need to implement anything else then clearly explain it in the first post of the question. Upvote 0
mohsyn said: Objective here is trap back key and close drawer if open else ask if user wants to exit without saving Click to expand... If this is the objective then the solution is here: https://www.b4x.com/android/forum/threads/b4x-b4xpages-b4xdrawer.120246/#content If you need to implement anything else then clearly explain it in the first post of the question.