Android Tutorial [B4X] OkHttpUtils2 with Wait For

Status
Not open for further replies.

MhdBoy

Member
Licensed User
Longtime User
hi
how i can call Release method for wait for in other subs?
i have an app that have lots of post and if i open a post and just close the post activity before load complete after i back to previous activity and Wait for done automaticaly
 

M.LAZ

Active Member
Licensed User
Longtime User


could i use Download2 with DownloadMany? because i have to send parameters with this request .
 

DonManfred

Expert
Licensed User
Longtime User
Please start a new thread for any question you have.

Instead of a list of URLs you can use a List of Maps (holding the url and all other parameters).
You can adapt downloadmany to add the additional parameters based on the Map-contents.
 

sorex

Expert
Licensed User
Longtime User
Thanks for the implementation of this wait for method.

It makes more sense to group the response code with the actual call instead of stuffing it all in the jobdone sub.
 

skaliwag

Member
Licensed User
Longtime User
Will the resources held by a HttpJob be automatically released when the HttpJob goes out of scope?
Previously, I would call HttpJob.Release when the activity was closed, in case the user closed the Activity while waiting for a download.
With the HttpJob now declared locally, this is no longer possible.
 
Last edited:

DonManfred

Expert
Licensed User
Longtime User
Previously, I would call HttpJob.Release when the activity was closed.
Using wait for you need to Release the job after the wait for.
NOT using wait for you must release it in JobDone.

B4X:
Dim j As HttpJob
j.Initialize("", Me)
j.Download("https://www.google.com")
Wait For (j) JobDone(j As HttpJob)
If j.Success Then
   Log(j.GetString)
End If
j.Release

or, using JobDone

B4X:
Sub JobDone (Job As HttpJob)
   Log("JobName = " & Job.JobName & ", Success = " & Job.Success)
   If Job.Success = True Then
      Select Job.JobName
         Case "Job1", "Job2"
            'print the result to the logs
            Log(Job.GetString)
         Case "Job3"
            'show the downloaded image
            Activity.SetBackgroundImage(Job.GetBitmap)
      End Select
   Else
      Log("Error: " & Job.ErrorMessage)
      ToastMessageShow("Error: " & Job.ErrorMessage, True)
   End If
   Job.Release
End Sub
As you can see; It is ALWAYS MANDATORY to release the Job.

Release when the activity was closed.
Sounds like an mistake to me.
 
Last edited:

skaliwag

Member
Licensed User
Longtime User
Yes, I would also put the Job releases where you have them.
The question is, what happens to the Job resources if the user closes an activity while we are waiting for JobDone to complete?
In this case, we would never get to the Job.Release.
This is why I also call Job.Release when the activity is closed.
 

desof

Well-Known Member
Licensed User
Longtime User
Is this available for B4A?
Where do I download an example of this simple?
 

desof

Well-Known Member
Licensed User
Longtime User

What is the correct place to determine if the image is correctly loaded in ImageView1 or ImageView2 and if something fails to be hidden?
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…