Android Question "Wait For" lots of sub finish, but need to BACK

peacemaker

Expert
Licensed User
Longtime User
Now the downloading files from Internet is very simple due to Wait For.
B4X:
Sub DownloadImage(Link As String, iv As ImageView)
    If InterruptDownloadingFlag Then Return 'stop, no more !
    Dim j As HttpJob
    j.Initialize("", Me)
    j.Download(Link)
    Wait For (j) JobDone(j As HttpJob)
    If InterruptDownloadingFlag Then Return 'stop !!!
    If j.Success Then
        iv.Bitmap = j.GetBitmap
    End If
    j.Release
End Sub

But if at Activity opening a loop starts 50... 100 times downloading some _optional_ for user files to be listed, if he wants. Again - files are just for optional viewing...

Downloading can be rather long, if many files... and depends on the Internet speed...
But if the user decided to go BACK, closing the Activity - now it's impossible ! As Activity re-started again.
Boolean flag in the downloading sub does not help.
If 5-10 files to be downloaded - it's OK, downloadings are finished fast.

How to stop "waiting for" such lot of subs ?
 
Last edited:

Erel

B4X founder
Staff member
Licensed User
Longtime User
The issue you encounter is not related to Wait For. It is related to HttpUtils2 behavior. It internally uses CallSubDelayed when the result is available and CallSubDelayed causes the activity to be resumed.

The solution is to make all requests from a service. Put this sub in the starter service and call it with CallSubDelayed3.
 
Upvote 0

peacemaker

Expert
Licensed User
Longtime User
Thanks, Erel. But anyway in this case the downloadings that are started - will not be interrupted ?
 
Upvote 0

peacemaker

Expert
Licensed User
Longtime User
no. The service will download them in the background
Yes, checked. Prev activity is slow while downloadings are working...
It means that in this case - the async downloading lot of images is a wrong way...

And ULV cannot help , as here horizontal scrollview must be used, by design.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…