Http2Uils2 - Sending 2 Jobs

bahamasc

Member
Licensed User
Longtime User
Http2Utils2 - Sending 2 Jobs

Dear all,

Just started using Basic4Android and so far so good. At the price, its a steal.

I have an app that
a) Allows the user to search a web database of items
b) Displays the results, a few fields, in a list view
All of this works fine with the httputils2.

When the User clicks on one of the items in the list view it takes the ID, queries for more details from the db along with a url of the image (from Amazon's API). This works however it only executes after end sub.

What I want to do is download the URL to cache and show it with the other details in a msgbox2 however the hc_success doesnt get triggered until the sub is done

Even if I try to call it in the JobDone its a little better but it doesnt fully run either.

I think this may be due to the CallSubdealyed2 not sure.

How do I have the click event run two http jobs and show the message box?

B4X:
Sub ListView1_ItemClick (Position As Int, Value As Object)
    Dim tl As TwoLines
    Dim intPipePos As Int
   Dim id As Int
   
    tl = Value
    
   intPipePos = tl.Second.LastIndexOf(":")
   id = tl.Second.SubString(intPipePos + 1)
   
   ExecuteRemoteQueryWithAmazon("SELECT id, insertdate, comments, isbn, handle, price, title, author, course_id, handle FROM `books` WHERE id=" & id, "Job2")
   DownloadImageToCache(url,"Job3")'This requires the URL from the above but the above is skipped and end sub is run
   'then I will download the image to chace and display iti n a msgbox2 as a bitmap   
   End Sub
Sub DownloadImageToCache(Query As String,TaskId As String)
    job3.Initialize(TaskId, Me)      
   job3.Download(Query)
   
End Sub
 
Last edited:

bahamasc

Member
Licensed User
Longtime User
Http requests are executed in the background (asynchronously). You should use JobDone sub to continue the program logic.

Thanks. But this is what I did.

In JobDone Sub I'd query the DB to get the URL and then run a download on the image, then call the message box to show the downloaded image. Problem is that it would run the run through the code first so it would try to call the message box and after the End Sub it would try to download the image. Problem is...the messagebox needs the downloaded image. It doesnt work in one shot.

Its implemented similar to the example in the HTTPUtil2 Job3 code. the difference is that the example given knows the URL before hand. So it makes the download based on the URL it knows. I'm trying to query the URL then download the image then display the message box with the downloaded image.

Either way I worked around it. I decided to not show the image in the message box but have a button as an option for the user to see the image. That way it doesnt run the download until the user makes another click.

Thanks.
 
Upvote 0
Top