Android Question [SOLVED] Save Map as File to Preload at Start Launch APP

scsjc

Well-Known Member
Licensed User
Longtime User
I would like to know if there is some easy way to save a map inside a file, and to be able to "preload" that map from the file, until the images are updated?
I use the map with the following code to keep in memory the bitmaps loaded from url:

B4X:
Sub Process_Globals
    Public cache As Map
End Sub
Sub Service_Create
    cache.Initialize
End Sub


public Sub Downloadimage(link As String, iv As ImageView)
    If cache.ContainsKey(link) Then
        Dim bmp As B4XBitmap = cache.Get(link)
        If bmp.IsInitialized Then iv.SetBackgroundImage(bmp.Resize(iv.Width,iv.Height,True))
    Else
        Dim job As HttpJob
        job.Initialize("", Me)
        job.Download(link)
        Wait For (job) JobDone(job As HttpJob)
        If job.Success Then
            Try
                Dim bmp As B4XBitmap = job.GetBitmap
                cache.Put(link, bmp)
                iv.SetBackgroundImage(bmp.Resize(iv.Width,iv.Height,True))
            Catch
                log(LastException)
            End Try
        End If
        job.Release
    End If
End Sub


Thanks :)
 

josejad

Expert
Licensed User
Longtime User
Hi scsjc:

In the map doc it says:
You can save and load maps with "simple values" with File.WriteMap and File.ReadMap. More complex maps can be saved with B4XSerializator.

So you can make some test with this
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
you can not store any map containing objects (in this case images).

You need to store the images seperately on disc and only store the path in the Map.
 
Upvote 0
Top