Search code examples
androidpersistent-storage

What's the method for storing arrays or custom objects (persistent data)?


Is there any way to store a custom data object as persistent data without employing SQLite in Android?

I have a 3*3 matrix of EditText fields on screen, and I want to store all the content of those 9 fields into one "profile" (object). Other profiles can be created to have a different matrix with different data.

I thought of XML, but I would like to hear other opinions.


Solution

  • You could serialize the array and store it to the shared preferences, similar to the answer to this question:

    Android Sharepreferences and array

    To store multiple profiles you could possibly store each in the shared preferences with a key like "Profile-1", "Profile-2", etc. You could then have another shared preference that has the number of Profiles you have.