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.
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.
You could try something like
public bool save(SaveableObject s, Context context, String fileName)
{
    try
    {
        FileOutputStream fos;
        ObjectOutputStream os;
        File file1 = context.getExternalFilesDir(null);
        File file2 = new File(file1, fileName);
        fileName = file2.getAbsolutePath();
        fos = context.openFileOutput(fileName, Context.MODE_PRIVATE);
        os = new ObjectOutputStream(fos);
        os.writeObject((Object)analysis);
        os.close();
        fos.close();
    } 
    catch (IOException e)
    {
        e.printStackTrace();
    }
}
which should save a file to /sdcard/fileName.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With