Hi all,
I'm not 100% sure what could be my best option when I have to download a very limited number (10 or 15) of small images on app start.
I'm aware of SMM and Imageloader, but in this case wouldn't it be preferable some classic code like below?
Keep in mind that it's executed just at app start and that only newer files need to be downloaded (so on absolute first app's execution they could be 10 or so, but on subsequent runs they would be zero to three at most).
Images will be stored locally and retrieved when needed (e.g to populate panels on a CLV). Eventually a B4xCache could be used to hold them in memory.
I'm not 100% sure what could be my best option when I have to download a very limited number (10 or 15) of small images on app start.
I'm aware of SMM and Imageloader, but in this case wouldn't it be preferable some classic code like below?
Keep in mind that it's executed just at app start and that only newer files need to be downloaded (so on absolute first app's execution they could be 10 or so, but on subsequent runs they would be zero to three at most).
Images will be stored locally and retrieved when needed (e.g to populate panels on a CLV). Eventually a B4xCache could be used to hold them in memory.
B4X:
'Called as:
'Wait For(SyncImages) Complete (Result As Object)
'in a chain of WaitFors used to update several items of the local DB
'ImgList contain a list of newer images to download
Sub SyncImages As ResumableSub
Dim remotedir As String = "<my server dir whre images ares tored>"
For i = 0 To ImgList.Size-1
DownloadAndSaveFile (remotedir&ImgList.Get(i), ImgList.Get(i))
Next
Return Null
End Sub
'Download remore image and save it locally
Sub DownloadAndSaveFile (Link As String, fname As String)
Dim j As HttpJob
j.Initialize("", Me)
j.Download(Link)
Wait For (j) JobDone(j As HttpJob)
If j.Success Then
Dim out As OutputStream = File.OpenOutput(DBFolder&"/images", fname, False)
File.Copy2(j.GetInputStream, out)
out.Close
End If
j.Release
End Sub
[code]
What do you think? Am I overlooking something basic?
Last edited: