Android Question WriteMap/ReadMap with List as value

msali

Member
Licensed User
Longtime User
Hi,
I have created a Map with a string as Key and List in Values - No issue.

B4X:
thisLst.InsertAt(typMapFld.Duration, 0)
thisLst.InsertAt(typMapFld.SeqLength, 1)
thisLst.InsertAt(typMapFld.Attempts, 2)
thisLst.InsertAt(typMapFld.isCurrentStage, 3)
thisLst.InsertAt(typMapFld.isCompleted, 4)
'
thisMap.Put(key, thisLst)
Then I save it using WriteMap

B4X:
File.WriteMap(SS_FilePath, "stages", thisMap)

After Saving it I try to read it with ReadMap and try reading the list stored in value

B4X:
mapStages= File.ReadMap(SS_FilePath, "stages")
thislst= mapStages.Get(key)

I am unable to read the list properly.

Where am I going wrong. Is this type of structure not allowed?

Thanks in adv.

Cheers :)
 

DonManfred

Expert
Licensed User
Longtime User
I am unable to read the list properly.

Where am I going wrong.
Check the documentation of File.WriteMap

https://www.b4x.com/android/forum/pages/results/?query=File.WriteMap
Method_636.png
File. WriteMap (Dir As String, FileName As String, Map As Map)

Creates a new file and writes the given map. Each key value pair is written as a single line.
All values are converted to strings.

You should use Randomaccessfile.writeb4xobject and Randomaccessfile.readb4xobject to read the map back.

https://www.b4x.com/android/help/randomaccessfile.html#randomaccessfile_readb4xobject

https://www.b4x.com/android/help/randomaccessfile.html#randomaccessfile_writeb4xobject
 
Upvote 0

msali

Member
Licensed User
Longtime User
See this video:
This exact issue is discussed starting from 25:00

Too good... I created a simple test project and it worked perfectly well.

Now tomorrow I will embed it in my main project.

Just Perfect.

Thanks a lot.
 
Upvote 0
Top