As i understood, resumable subs are running in the main thread. I have a small procject with a tablayout. In each tab (3) i have a scroll view with some imageviews, that download a thumbnail from a server and load the bitmap. For achieve this, i have a single routine that load the image. Each image calls a sub to download the image, located in starter service, and wait the download. When i try to download, the device will become a bit unresponsive. Is there a way to load the bitmaps meanwhile they are downloaded, without blocking UI?
Thanks, sorry for my english
Thanks, sorry for my english
B4X:
'Place image view sub
Sub loadScv
....
ListOfFiles = parser.NextArray
For Each v As String In ListOfFiles
Dim itm As Item = Utils.GetItemFromString(v)
AddNewItem(itm)
lstFile.Add(itm)
Sleep(0)
Next
End sub
B4X:
Sub AddNewItem(itm As Item)
'....
'.. add panel, imageview and other on scv....
'....
If File.Exists(Utils.DirThumb,itm.name&extension) Then
FillImageToView(LoadBitmap(Utils.DirThumb,itm.name&extension),im)
Else
Wait For (CallSub2(Starter,"Download",Utils.UrlThumbnail&"/"&itm.name&extension)) Complete(j As HttpJob)
If j.Success Then
FillImageToView(j.GetBitmap,im)
Dim out As OutputStream = File.OpenOutput(Utils.DirThumb,itm.name&extension,False)
j.GetBitmap.WriteToStream(out,100,"PNG")
out.Close
End If
End If
Sleep(0)
End Sub
B4X:
'Starter service
Sub Download(url As String) As ResumableSub
Dim j As HttpJob
j.Initialize("",Me)
j.Download(url)
wait for (j) JobDone(j As HttpJob)
Return j
End Sub