Android Question MsgBox2Async correct use

GiovanniPolese

Well-Known Member
Licensed User
Longtime User
Hi to all
since the introduction of asyncronous msgboxes, i lost a good part of love for B4A. As a matter of fact, a trivial action like to wait for user interaction, normally managed in "Modal" style (Windows Modal, I mean) became a nightmare, expecially in previous code written with "obsolete" MsgBoxes. My understanding is that, in practice, I must make Apps more or less without relying on the fact that the App waits for user answers. This adds real difficulties to my common Apps. Therefore I decided to try to understand better my faults on this subject, submitting to this community my problem. In the attached code, I have a List, that needs to be changed on User's choice. This code doesn't work, because the ModifyList returns immediately. Maybe the solution is to let the ModifyList sub to wait too.. but it is not so clear to me what to do.
Thanks in advance

B4X:
Private Sub Button1_Click
    Dim i As Int
 
   List1.Initialize
    
    For i=0 To 10
        List1.Add(i+1)
    Next
    
    Log("Before")
    For i=0 To 10
        Log(List1.Get(i))
    Next
    
    ModifyList(List1)
    
    Log("After")
    For i=0 To 10
        Log(List1.Get(i))
    Next
    
End Sub

private Sub ModifyList(L As List)
    Wait for (Confirm("Modify List?")) Complete (Res As Int)
    If Res=DialogResponse.POSITIVE Then
        Dim i As Int
        For i=0 To 10
            L.Set(i,10-i)
        Next
    End If
End Sub

private Sub Confirm(Msg As String) As ResumableSub
    Dim Res As Int
    Msgbox2Async(Msg, "Attention", "Yes", "", "No",Null, False)
    Wait For Msgbox_Result (Res As Int)
    Return Res
End Sub
 

Attachments

  • TestAsyncMsgbox.zip
    10.1 KB · Views: 199

MrKim

Well-Known Member
Licensed User
Longtime User
Hi. I don't discuss the importance of the resumable subs etc (for anybody else than me). Only, as a seasoned Windows programmer, and not loving particularly Android, I had this difficulty. Nevertheless, forgive me: all this noise for deprecating MsgBoxes, which are substantially Modal DIalogs (and also Modal way is basically deprecate in B4A, and Android, as I learned now)? What sounded strange to me was the fact that the lack of Modal stuff was passed as "normal". In my Apps, 99% of dialogs and message boxes are Modal. Probably I didn't understand well the sitation. If I knew since the beginning that I must work always asyncronously, I could have done many things differently. I have many Apps with serial or internet communication which work asyncronously, with no problem. It was clear since the beginning and I did. Finding myself to manage the MsgBox deprecation was annoying, to be sincere. Ok. This is my problem, anyway. Luckily one of the best things of B4A is .. its community.. Thanks to all.
As a seasoned Windows programmer I feel your pain. It has been hard getting used to HAVING to do things Async.
 
Upvote 0
Top