Android Question B4XPages - handling the back key

Patrick Clark

Active Member
Licensed User
how can i handle the "back" key on pages that don't have a parent. ie. they have been displayed with
B4X:
B4XPages.ShowPageAndRemovePreviousPages

On a page with a parent I can use
B4X:
Private Sub B4XPage_CloseRequest As ResumableSub
     Return False
End Sub

But if the page that is currently displayed is the only page in the stack the app crashes when i press the back key
 

mangojack

Well-Known Member
Licensed User
Longtime User
Do you have this line in the 'Main' module ... ?
B4X:
Sub Activity_KeyPress (KeyCode As Int) As Boolean    
    Return B4XPages.Delegate.Activity_KeyPress(KeyCode)    
End Sub

If so remove it .

 
Upvote 0

mangojack

Well-Known Member
Licensed User
Longtime User
Probably more correct is to keep this code in the 'Main' module ...
B4X:
Sub Activity_KeyPress (KeyCode As Int) As Boolean  
    Return B4XPages.Delegate.Activity_KeyPress(KeyCode)  
End Sub


and in your Pages class module handle the back key in the Close_Request event.
B4X:
Sub B4XPage_CloseRequest As ResumableSub  
    Return True
End Sub


ps: strangely , In a similar scenario test app, passing Return False did not cause a crash (as in your case) , just made back key unresponsive.
 
Upvote 0

Patrick Clark

Active Member
Licensed User
I do have everything as you have said apart from the Return False

The behaviour I want is to ignore the back key (unresponsive) but I get a crash.
 
Upvote 0
Top