Sub Activity_KeyPress(KeyCode As Int) As Boolean
If KeyCode = KeyCodes.KEYCODE_BACK Then
Dim result As Int
result = Msgbox2("msg", "title", "yes","cancel","no", Null)
If result=DialogResponse.NEGATIVE Then
ToastMessageShow("do not exit",False)
Return True
Else If result=DialogResponse.positive Then
ToastMessageShow(" exit",False)
how could the messagebox2 block the back button to be pressed again and override the messagebox itself?
Sub Activity_KeyPress (KeyCode As Int) As Boolean 'Return True to consume the event
If KeyCode = KeyCodes.KEYCODE_BACK Then
Dim result As Int
result = Msgbox2 ("App Exit?","","Yes","","No",Null)
If result=DialogResponse.POSITIVE Then
Activity.finish
Else If result=-3 Then 'Add this to recapture back button pressed while MsgBox is shown
Return True
Else
Return True
End If
End If
End Sub
Yes it will. But this way if i don't for example to exit an activity by means of the back button, pressing back will show a messagebox, pressing it again will make the messagebox close, pressing back once more will make the messagebox re-appear and so on...
Sub Activity_KeyPress (KeyCode As Int) As Boolean 'Return True to consume the event
If KeyCode = KeyCodes.KEYCODE_BACK Then
Dim result As Int
result = Msgbox2 ("App Exit?","","Yes","","No",Null)
If result=DialogResponse.POSITIVE Then
Activity.finish
Else If result=-3 Then 'Add this to recapture back button pressed while MsgBox is shown
Return True
Else
Return True
End If
End If
End Sub
I think that the 'else if result=-3' is not needed, since you are consuming the 'cancel' keystroke. Of course I may be missing something here, in means of what you actually want to achieve.
Ok, I've read more carefully your post and Erel's reply. Is this, perhaps, what you want to achieve?
B4X:
Sub Activity_KeyPress (KeyCode As Int) As Boolean 'Return True to consume the event
If KeyCode = KeyCodes.KEYCODE_BACK Then
showExitDialogBox
Return True
End If
End Sub
Sub showExitDialogBox
Dim result As Int
result = Msgbox2 ("App Exit?","","Yes","","No",Null)
Select result
Case DialogResponse.POSITIVE
Activity.Finish
Case DialogResponse.CANCEL
showExitDialogBox
End Select
End Sub