Keycode_back

sktanmoy

Active Member
Licensed User
Longtime User
I use this for one of my current app.

B4X:
Sub Activity_KeyPress (KeyCode As Int) As Boolean
Select KeyCode
        Case KeyCodes.KEYCODE_BACK
      Dim m As Int
      m = Msgbox2("Are you sure to close this app?", "Confirmation", "Yes", "", "No", Null)
      If m = DialogResponse.POSITIVE Then
         ExitApplication
      Else
         Return True
      End If
End Select

End Sub

I saw most of the apps use a toastermessage saying "Press back key again to exit"

Here I can easily show that message after single back button click. But how can I detect second button press to exit the app?
 

lagore

Active Member
Licensed User
Longtime User
Use an indicator say a Boolean that is set to false when the activity is started then in 'Activity_KeyPress' test the boolean if false display your toast message and set the boolean to true, next time around with the test being true allow the back key do its job. If you wanted to be really annoying and have it happen a few times you could use a counter with a 'case' statement and different toast messages.
 
Upvote 0

tsteward

Well-Known Member
Licensed User
Longtime User
Im a bit new at this so possible dumb question.

You set flag to true and if Back is pressed a second time you do nothing just allow the app to close.

If they do not press Back where would you reset the flag back to False?
 
Upvote 0
Top