Download multiples files with service module

rclatorre

Member
Licensed User
Longtime User
Erel, my program scans a table containing the articles in a publication of a journal and uses a service to download pictures of each item (2 for each item).

The problem I've found is that when I run the application only download the image of the last article.

Apparently, as the Service is called multiple times, this overwriting service parameters (url_source and file_name) and just run the last.

Is there any other form of download multiple images at once using a service.?


Main code

B4X:
For i = 0 To articles.Size - 1
   Dim m As Map
   m = articles.Get(i)

   'Imagenes
   Dim image_top_url As String
   Dim image_bottom_url As String

   image_top_url=m.Get("image_top_url")

   If image_top_url.Length>0 Then
      DownloadImage.url_source=m.Get("image_top_url")
      DownloadImage.file_name="a_"&m.Get("article_id")&"Top.jpg"
      StartService(DownloadImage)
   End If

....

DownloadImage Service Module
B4X:
Sub Process_Globals
     Dim url_source As String
     Dim file_name As String
End Sub

Sub Service_Create

End Sub

Sub Service_Start (StartingIntent As Intent)
                  
   Dim job1 As HttpJob
   job1.Initialize("Job"&file_name, Me)
   job1.Tag = file_name 
   
   job1.Download(url_source)

End Sub

Sub Service_Destroy

End Sub

Sub JobDone (Job As HttpJob)
   If Job.Success = True Then
      Dim out As OutputStream
      out = File.OpenOutput(File.DirDefaultExternal, Job.Tag, True)
      File.Copy2(Job.GetInputStream,out)
      out.Close
   Else
      Log("Error: " & Job.ErrorMessage)
      ToastMessageShow("Error: " & Job.ErrorMessage, True)
   End If
   Job.Release
End Sub

Thanks

Roberto
 
Top