Android Question saving/loading a bunch of lists and objects?

Dave O

Well-Known Member
Licensed User
Longtime User
What's the recommended way to save to file (and later reload) data in the form of objects, some of which contain lists of other objects?

My previous apps had modest data needs, so I could just read/write maps from/to a text file. Easy.

However, my new app has a lot of classes that include not just primitives but also lists of other objects, which in turn have lists of yet more objects. (That is, a non-trival data model.)

One more fun twist is that the objects contain references to each other, so I can easily navigate from one to another. (e.g. a player has a list of poker hands, and a poker hand also links back to the player)

Ideally I'd like to use something like B4XSerializator to save the objects to a file (via bytes, I assume). I know there are other possibilities too, like SQLite (although I'd like to avoid SQL if I can - I just need load/save, not queries).

However, I don't know how B4XSerializator would handle objects that link to other objects, or circular references like I described above.

Any tips greatly appreciated. Thanks!
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Classes cannot be serialized automatically with B4XSerializator. You can create a sub that returns a custom type from a class instance and then save these types.

B4XSerializator will not work with circular references. I recommend you to add all objects as keys to a map with the custom types as the values. This way you can deal with circular references.

The next step is to add all values to a List and save the list with B4XSerializator or KVS2 (which is based on B4XSerializator).
 
Upvote 0
Top