httpjob : jobdone question...

ahwong

Member
Licensed User
Longtime User
I have many images on the web,

http://examples.com/images/100.jpg to
http://examples.com/images/999.jpg

and I want to download them to File.DirRootExternal using the code below..
It works if the image file sizes are small or smaller For-Next loop..

But if I want to download more images with bigger file sizes, the JoneDone will misfired.. Any idea where I made the mistake? Thank you.

B4X:
Sub Process_Globals
  Dim MainUrl As String
  MainUrl = "http://examples.com/images/"
End Sub

Sub Activity_Create(FirstTime As Boolean)
  Dim i As Int
  Dim image As String
  For i=100 To 999
    Dim job As HttpJob
    image=i&".jpg"
    job.Initialize(image, Me)
    job.Download(MainUrl & image)
  Next
  Msgbox("done","")
End Sub

Sub JobDone(Job As HttpJob)
  If Job.Success = True Then
    Dim out As OutputStream
    out=File.OpenOutput(File.DirRootExternal,Job.JobName,False)
    Job.GetBitmap.WriteToStream(out,100,"JPEG")
  Else
     Log("Error: " & Job.ErrorMessage)
     ToastMessageShow("Error: " & Job.ErrorMessage, True)
  End If
End Sub
 
Top