B4J Question (Non-UI Application) JobDone never get called

somed3v3loper

Well-Known Member
Licensed User
Longtime User
In this simple code , jobDone never get called .
What am I missing ?
I tried with and without Wait For
HttpUtils2_NONUI(Version 2.62)
B4X:
Sub AppStart (Args() As String)

    
    
    Dim j As HttpJob
    j.Initialize("", Me)
    j.Download("https://en.wikipedia.org/w/api.php?format=json&action=query&prop=extracts&exintro=&explaintext=&titles="&"b4x")
    Wait For(j) JobDone(j As HttpJob)
    If j.Success Then
        'work with result
        Log("Wait For(j) JobDone"&j.GetString)
    Else
        Log("Err")
    End If
    j.Release
    
    
    StartMessageLoop
    
    
    
End Sub
 

somed3v3loper

Well-Known Member
Licensed User
Longtime User
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Quoting the tutorial:

The Handle AppStart sub cannot be a resumable sub itself.

Why?

- Wait For / Sleep must be called before the call to StartMessageLoop or they will never be executed.
- Wait For / Sleep code flow is equivalent to Return so if they appear before StartMessageLoop then the message loop will never be created and the handler will complete before the event is raised.

B4X:
Sub AppStart (Args() As String)

    Download
    StartMessageLoop
    
End Sub

Sub Download
  Dim j As HttpJob
    j.Initialize("", Me)
    j.Download("https://en.wikipedia.org/w/api.php?format=json&action=query&prop=extracts&exintro=&explaintext=&titles="&"b4x")
    Wait For(j) JobDone(j As HttpJob)
    If j.Success Then
        'work with result
        Log("Wait For(j) JobDone"&j.GetString)
    Else
        Log("Err")
    End If
    j.Release
 
Upvote 0
Top