Android Question Don't Stop the application

Dogbonesix

Active Member
Licensed User
It might be too easy but I don't know how. I keep pressing the return button on my application - inadvertently - too many times and exit the application. I know it is no big a deal but I would like to get a warning just before I exit. Is there code to flag that I am exiting the last activity? One solution is to start with a Splash screen - which might be a good idea but I would like to avoid the trouble.
 

NJDude

Expert
Licensed User
Capture the BACK key, like this:
B4X:
Sub Activity_KeyPress(KeyCode As Int) As Boolean 'Return True to consume the event

    If KeyCode = KeyCodes.KEYCODE_BACK Then

       If Msgbox2("Exit app?", "Confirmation", "Yes", "", "No", Null) = DialogResponse.POSITIVE Then

          Activity.Finish

       End If

    End If
 
    Return True

End Sub
Add that routine to the MAIN activity.
 

Dogbonesix

Active Member
Licensed User
I'll give that a try - I thought about that but I figured "That's too simple" So I was trying a more complicated wrong way. Thanks.
 

Dogbonesix

Active Member
Licensed User
Opps, the code above actually hide my Menu - for some odd reason - so I modified it a bit.

Sub Activity_KeyPress(KeyCode As Int) As Boolean 'Return True to consume the event
If KeyCode = 4 Then ' KeyCodes.KEYCODE_BACK Then
If Msgbox2("Exit app?", "Confirmation", "Yes", "", "No", Null) = DialogResponse.POSITIVE Then
Activity.Finish
Else
Return True
End If
End If
End Sub
 
Top