Android Question Saving a JavaObject in a key value store (or other method)?

ac9ts

Active Member
Licensed User
Longtime User
I am using the ExternalStorage class to manipulate ~3000 data files on a SD card. When the app starts, it will read the data directory and map the files by name as ExternalFile types. I then use the map to access the files while the app is running.
B4X:
Type ExternalFile (Name As String, Length As Long, LastModified As Long, IsFolder As Boolean, Native As JavaObject)
The problem is, the initial scan to load the map takes 2-3 minutes. I would like to save the map so it doesn't have to be regenerated every time.

I tried File.WriteMap but it converts the object to text and it doesn't come back properly with File.ReadMap

I also tried using the KeyValueStore class to store the ExternalFile type. I also tried just tried just storing the Native JavaObject. Both of these had errors when reading back the value (error converting Object to JavaObject).

Any recommendations on storing a map/list/etc. of ExternalFile types?
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
The question in the title cannot be answered as it depends on the actual type that is saved in the JavaObject wrapper.

The underlying DocumentFile cannot be serialized. It must be created at runtime. However you can create your own type with the other fields and store them. Later when you need to access a specific file, call FindFile to get the ExternalFile type.

You should of course use KVS2 to save a list or map with all the data.
 
Upvote 0

ac9ts

Active Member
Licensed User
Longtime User
I have a separate list of all the filenames and previously used FindFile to get the ExternalFile type. That transaction would take a few seconds to run. That's why I was looking for a way to read in all the ExternalFile descriptors and save them. I was hoping to remove the individual FindFile call delays.
 
Upvote 0
Top