Android Question Map and list saved to file?

Scantech

Well-Known Member
Licensed User
Longtime User
I have a numerous of Maps and List need to be saved to 1 file. I know how to save them individually, but it just creates numerous of files. I searched and did not come up with a solution.
 

Scantech

Well-Known Member
Licensed User
Longtime User
B4X:
Private Sub Button1_Click
    Dim lContainer As List
    lContainer.Initialize
    
    'Map and List data need to be saved
    Dim m As Map
    m.Initialize
    m.Put("MapKey", "Value 1")
    
    Dim l As List
    l.Initialize
    For g = 0 To 200
        l.Add(g)
    Next
    
    lContainer.Add(m)        'index 0 contains maps
    lContainer.Add(l)        'index 1 contains arrays of list
        
    Dim DataBuffer() As Byte
    Dim Ser As B4XSerializator
    DataBuffer = Ser.ConvertObjectToBytes(lContainer)
    File.WriteBytes(File.DirInternal, "Test.dat", DataBuffer)
    
    Dim DataBuffer2() As Byte
    Dim Ser2 As B4XSerializator
    DataBuffer2 = File.ReadBytes(File.DirInternal, "Test.dat")
    
    Dim GetObjectList As List
    GetObjectList = Ser2.ConvertBytesToObject(DataBuffer2)
    
    'Get Map from index 0
    Dim m2 As Map
    m2.Initialize
    m2 = GetObjectList.Get(0)
    Log(m2)
    Log(m2.Get("MapKey"))
    Log(m2.Size)
    
    'Get List from index 1
    Dim l2 As List
    l2.Initialize
    l2 = GetObjectList.Get(1)
    Log(l2)
    Log(l2.Size)

End Sub

Thanks. i learned something new today.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…