Sub Activity_KeyPress(KeyCode As Int) As Boolean
If KeyCode = KeyCodes.KEYCODE_BACK Then
Selection = Msgbox2("Do you want to save your changes?", "Exit", "Yes", "", "No", Null))
...
When you press back when editing the default behaviour is to close the keyboard. I think I understand you correctly though.
B4X:
Sub Activity_KeyPress (KeyCode As Int) As Boolean
If KeyCode = KeyCodes.KEYCODE_BACK Then
If Edittext1.Text <> "" Then
Dim a As Int
a = Msgbox2("Do you want to save?","Save","Yes","Cancel","No",Null)
If a = DialogResponse.POSITIVE Then
'Save
Else If a = DialogResponse.CANCEL Then
Return True
End If
End If
Return False
Else
Return False
End If
End Sub
This will stop the activity from closing when back is pressed and if there is text in edittext1 the msgbox will show. If the user selects:
Sub Activity_KeyPress (KeyCode As Int) As Boolean
Select KeyCode
Case KeyCodes.KEYCODE_BACK
If GlobalSender.IsInitialized Then
verif_valid(GlobalSender)
End If