Android Question How to control the flow of the HttpJob?

Hanz

Active Member
Hello,

With HttpJob, we write code like this:
B4X:
Dim j As HttpJob
...
Wait For (j) JobDone(j As HttpJob)
If j.Success Then
  foo()
else
  ...
end if
bar()
This will run the bar() even the foo() is not finished. Is there a way to let the foo() finished before the bar() begins?

Thanks!
 

Andrew (Digitwell)

Well-Known Member
Licensed User
Longtime User
The only reason that bar will run before foo is finished it if foo is a resumable sub.

If it is use Wait For (like line 3) to wait for foo to finish.

Take a look at the tutorial
 
Upvote 2

Hanz

Active Member
The only reason that bar will run before foo is finished it if foo is a resumable sub.

If it is use Wait For (like line 3) to wait for foo to finish.

Take a look at the tutorial
Even if there is no foo() but just waiting for some data, e.g. job.GetBitmap, job.GetString, etc. the bar() is executed immediately even the codes between the if and else are not yet finished. For instance, you are downloading a huge image, it's supposed to wait for the image to be downloaded first before the bar() is executed. But it's not. It will execute the bar() while the image is being downloaded.
 
Upvote 0

Andrew (Digitwell)

Well-Known Member
Licensed User
Longtime User
Very odd. Can you create a sample program to demonstrate

Here is some code pulled from a working program.
Job.release is never called before ParseconnectionsReturn.

B4X:
    Private job As HttpJob
    Private ret As List
    LastError = ""
    If (WantReadWrite) Then
        s = "/true"
    Else
        s = "/false"
    End If
    
    job.Initialize("",Me)
    job.Download(strURLGetConnections&s)
     Wait For (job) JobDone(job As HttpJob) : LastResponseCode = job.response.Statuscode
    
    If job.Success Then
        ret = ParseConnectionsReturn(job.getstring)
    Else
        Private t As String = job.ErrorMessage
        ReleaseLog.DoReleaseLog("Update user settings : " & t)
        LastError = t
        ret.Initialize
    End If
    job.Release
    
    Return ret
 
Upvote 0
Top