Android Question [SOLVED] Wait For on a callback?

techknight

Well-Known Member
Licensed User
Longtime User
I am writing an app which puts some of the UI elements in classes to make things easier for me, and to help prevent spagetti code.

So, I have a subroutine in a class like this:

B4X:
Private Sub cmdChooseFile_Click
    If SubExists(Callback, "PlaylistPage_GetFile") = True Then
        TempFile.Initialize
        Dim M As Map = CallSub(Callback, "PlaylistPage_GetFile") '<--Wait For this 100%
        TempFile.ID = DateTime.Now
        TempFile.Name = M.Get("FileName")
        TempFile.FileName = TempFile.Name
        TempFile.FileType = M.Get("FileType")
        TempFile.Thumbnail = M.Get("Thumbnail")
        txtDuration = M.Get("Duration")
    Else
        Log("Unimplemented GetFile Handler")
    End If
End Sub

Now I saw the "As ResumableSub" tutorial, but I was wondering if its possible to do a Wait For on a Callback like this? Basically if my Event in Main (callback) has an Async listview dialog or something, I dont want any of that return code running until that GetFile Event is 100% complete.

My immediate thought was this:
B4X:
Wait For (CallSub(Callback, "PlaylistPage_GetFile")) Complete (M As Map)

But I have not tried it.

thoughts? Do I define GetFile as resumable sub? But its in a different context, hence the callback.
 
Last edited:

Erel

B4X founder
Staff member
Licensed User
Longtime User
PlaylistPage_GetFile should return a ResumableSub.

The best way to call a resumable sub with CallSub is:
B4X:
Dim rs As ResumableSub = CallSub(...)
If rs.IsInitialized Then
 Wait For (rs) Complete (M as Map)
 
End If
rs will not be initialized if the CallSub call failed. This can happen for example if the target activity is paused.
 
Upvote 0
Top