Android Question Trapping "Cancel" button

Bernhard Svavarsson

Member
Licensed User
Longtime User
I am using the following code to trap "back-button".
It works for the "dialogResponse.Positive" that is the program terminates.
but for "dialogResponse.CANCEL" I need to close the message and the Program
should stay active. What parameter should I use to respond to "Cancel" without
affecting the program itself. Need only to close the Message and the Program stays active. ?

Sub Activity_Keypress (KeyCode As Int) As Boolean
Dim Answ As Int
Dim Txt As String
Log(KeyCode)

If KeyCode=KeyCodes.KEYCODE_BACK Then
Txt = "Do you really want to Quit the Program ?"
Answ=Msgbox2(Txt,"ATTENTION","Yes","","Cancel",Null)
If Answ=DialogResponse.POSITIVE Then
ExitApplication
End If
If Answ=DialogResponse.CANCEL Then
---------????

End If
End If
End Sub

Regards

Benni
 

klaus

Expert
Licensed User
Longtime User
B4X:
Sub Activity_Keypress (KeyCode As Int) As Boolean
    Dim Answ As Int
    Dim Txt As String

    If KeyCode=KeyCodes.KEYCODE_BACK Then
        Txt = "Do you really want to Quit the Program ?"
        Answ=Msgbox2(Txt,"ATTENTION","Yes","Cancel","",Null)
        If Answ=DialogResponse.CANCEL Then
            Return True
        End If
    End If
    Return False
End Sub
Attention ! You must put Cancel to the middle Button, or test DialogResponse.NO.
Don't use ExitApplication.
 
Upvote 0

Bernhard Svavarsson

Member
Licensed User
Longtime User
Hi Klaus
Many thanks for this - tested this code on the SQLExample program.
The "Cancel" works fine.
If I press button "yes" it closes the program as supposed but if program is started again (on Device)
a DiskIOException error appears (code 1802). Any thoughts ?

Regards

Benni
 
Upvote 0
Top