Question

Hi: I've got a custom class and I want to save it to an Assests file. The reason I want to do this is to be able to restore the state of my program with ease at the touch of a button. Basically I have a bunch of String lists and simple strings and numbers collected in a class and I want to write a function that will write all of that in the Assets file. I wanted to implement this by having the class implement Parcelable and using its methods for writing in the open file, the raw data. However while reading the documentation I came across this line:

This class (and the corresponding Parcelable API for placing arbitrary objects into a Parcel) is designed as a high-performance IPC transport. As such, it is not appropriate to place any Parcel data in to persistent storage: changes in the underlying implementation of any of the data in the Parcel can render older data unreadable.

Which kind of got me wandering if there is a better way? I don't want to write the file as text as I feel that would be terribly inefficient. Any other ideas? Thank you very much in advance....

Was it helpful?

Solution

As you seem to understand, persisting Parcelable data is a bad idea.

You probably don't really want to persist your data in text files on external storage in most cases.

You'd probably be best served to use a database. Here is a link to a SQLite tutorial that should get you started.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top