Android Question Trap close request with Msgbox2Async?

agraham

Expert
Licensed User
Longtime User
I've been coding all day and my mind is probably a bit tangled up as I am suffering a blind spot. In the old days we would use a modal Msgbox2 to block a close request event until the user decides and closes the dialog..
B4X:
Sub Activity_KeyPress (KeyCode As Int) As Boolean 'return true if you want to consume the event
    If KeyCode = KeyCodes.KEYCODE_BACK Then
        Dim res As String = Msgbox2("Do you really want to exit?", "", "Yes", "", "No", Null)
        If Not(res = DialogResponse.POSITIVE) Then Return True
        CheckSave
    End If
    Return False
End Sub
In the brave new world of Msgbox2Async how do we achieve the same thing? Can we achieve the same thing?
 

Mahares

Expert
Licensed User
Longtime User
Msgbox2Async how do we achieve the same thing?
Here is a possible solution Andrew:
 
Upvote 0

agraham

Expert
Licensed User
Longtime User
Sorted it with this. Is there a better way?
B4X:
Sub Activity_KeyPress (KeyCode As Int) As Boolean
    If KeyCode = KeyCodes.KEYCODE_BACK Then
        Activity_Close(KeyCode)
    End If
    Return True
End Sub
    
Sub Activity_Close (KeyCode As Int) As ResumableSub
    If KeyCode = KeyCodes.KEYCODE_BACK Then
        Msgbox2Async("Do you really want to exit?", "", "Yes", "", "No", Null, False)
        Wait For Msgbox_Result (Result As Int)
        If Result = DialogResponse.POSITIVE Then
            Activity.Finish
        End If
    End If
    Return False
End Sub
 
Upvote 0
Top