Android Question How to take over the Android bottom bar back/close button?

RB Smissaert

Well-Known Member
Licensed User
Longtime User
On my phone (S9) the android bottom navigation bar (not a b4a bar) back button (on my phone on the right hand side) functions as a back to previous screen button, unless you are in the main page of the app. See for example WhatsApp. How can I do the same in my b4a app, without replacing the Android bottom navigation bar?

RBS
 

MarkusR

Well-Known Member
Licensed User
Longtime User
something like this
(but with this example if user click 2x back it still exist.)
B4X:
Sub Activity_KeyPress (KeyCode As Int) As Boolean
    'Return True to consume the event
    Private Answ As Int
    If KeyCode = KeyCodes.KEYCODE_BACK Then
        Answ = Msgbox2("Do you want to quit the program ?", "A T T E N T I O N", "Yes", "", "No", Null)
        If Answ = DialogResponse.NEGATIVE Then
            Return True
        End If
    End If
    Return False
End Sub
 
Upvote 0

RB Smissaert

Well-Known Member
Licensed User
Longtime User
something like this
(but with this example if user click 2x back it still exist.)
B4X:
Sub Activity_KeyPress (KeyCode As Int) As Boolean
    'Return True to consume the event
    Private Answ As Int
    If KeyCode = KeyCodes.KEYCODE_BACK Then
        Answ = Msgbox2("Do you want to quit the program ?", "A T T E N T I O N", "Yes", "", "No", Null)
        If Answ = DialogResponse.NEGATIVE Then
            Return True
        End If
    End If
    Return False
End Sub

Very nice! That does exactly what I wanted.
Didn't come across this problem:
if user click 2x back it still exist
In my situation:

B4X:
Sub Activity_KeyPress(KeyCode As Int) As Boolean
If iCurrentPanelType = 0 Then
    Return False
Else
    GotoPanel(arrBackPanel(iCurrentPanelType), True)
    Return True
End If
End Sub

RBS
 
Upvote 0
Top