Android Question Cancel Image Download

khwarizmi

Active Member
Licensed User
Longtime User
Hi all
I'm using this code to download a number of images in a list, one by one:

B4X:
' img is an array of ImageViews, ImageView.tag is the url of the image
Do While i<=(img.Length-1)
            Dim j As HttpJob
            j.Initialize("", Me)
            j.Download(img(i).tag)
         
            Wait For (j) JobDone(j As HttpJob)
            If j.Success Then
                Dim out As OutputStream = File.OpenOutput(File.DirInternal, i & ".jpg", False)
                File.Copy2(j.GetInputStream, out)
                out.Close
                Dim bm As Bitmap
                bm.Initialize(File.DirInternal, i & ".jpg")
                i=i+1
             
            End If
        Loop

The problem is that if the user presses the back button, the application will return again to complete the download
How can I cancel this downloads?

Thanks
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Upvote 0

khwarizmi

Active Member
Licensed User
Longtime User
thanks.
The best and most comprehensive solution for me is to move the download related code to the starter service.
 
Upvote 0
Top