Android Question Using JobDone

Carthalion

Member
Licensed User
Longtime User
This works great! However, I plan to download multiple files. In a effort to minimize unnecessary code, is the SubJobDone required for each download. Or is there a way to download several files in one procedure?

Also, it works but...what is the "j"?

Sub Button1_Click
Dim Job As HttpJob
Job.Initialize("j", Me)
Job.Download("http://www.myUrl.com/myFile.txt")
End Sub

Sub JobDone(job As HttpJob)
If job.Success Then
Dim out As OutputStream = File.OpenOutput(File.DirRootExternal, "myFile.txt", False)
File.Copy2(job.GetInputStream, out)
out.Close '<------ very important
ToastMessageShow("File Downloaded Sucessfully!", True)
Else
Log("Error: " & job.ErrorMessage)
End If
job.Release
End Sub
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Please use [code]code here...[/code] tags when posting code.

Also, it works but...what is the "j"?
This is the JobName.

B4X:
Sub Button1_Click
   Dim Job1 As HttpJob
   Job1.Initialize("job1", Me)
   Job1.Download("http://www.myUrl.com/myFile1.txt")
   Dim Job2 As HttpJob
   Job2.Initialize("job2", Me)
   Job2.Download("http://www.myUrl.com/myFile2.txt")
   Dim Job3 As HttpJob
   Job3.Initialize("job3", Me)
   Job3.Download("http://www.myUrl.com/myFile3.txt")
   For i = 1 To 10
     Dim j As HttpJob
     j.Initialize("j" & i, Me)
     j.Download(...)
   Next
End Sub

Sub JobDone(job As HttpJob)
   If job.Success Then
     Select job.JobName
       Case "job1"
         Log(job.GetString)
       Case "job2"
         '...
       Case "job3"
         '...
     End Select
   End If
   job.Release
End Sub
 
Upvote 0
Top