Android Question [B4xPages] - downloading very few images

udg

Expert
Licensed User
Longtime User
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.

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:

LucaMs

Expert
Licensed User
Longtime User
I always ask myself too many doubts, but you are beating me.

What's the problem, since you've done it? At most you could show an animated splash screen while downloading.

Just a while ago I noticed a "conceptual error" in an app. In it, at the end of a step, an advertising video is displayed; well, I prefer to close and restart the app, since it takes less time to start than the duration of the videos!
 
Upvote 0

udg

Expert
Licensed User
Longtime User
What's the problem, since you've done it?
I'm not 100% sure what could be my best option. In the past I used all of the mentioned alternatives, but I feel some of those could a bit overwhelming foe the case at hand.
Read it as a call for some advice. Anyway, thank you for your reply.
 
Upvote 0

udg

Expert
Licensed User
Longtime User
Thanks @Erel
Do you think that SMM is anyway preferable even in this specific case? There's no grid, imageview or similar component used to show more or less "on the fly" the downloaded images.
It is more a resources downloading. Similar to those tiny icons that we generally put in DirAsset.
Problem here is that I don't know in advance which icons/images will be needed so the app has to collect them at runtime and store them locally for future reuse.
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
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.
Why do it yourself when it is already implemented in SMM?
Don't preload anything and don't think too much about the images. Simply add placeholder panels for the images and use SMM to show the images.
 
Reactions: udg
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…