What is the method of storing arrays or user objects (persistent data)?

Is there a way to save a custom data object as persistent data without using SQLite in Android?

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

I was thinking about XML, but I would like to hear other opinions.

+5
source share
3 answers

You can serialize the array and save it in general preferences, similar to the answer to this question:

Android Sharepreferences and Array

, , "-1", "-2" .. , , .

+3

-

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();
    }
}

/sdcard/fileName.

+2

Your options are described in the Data Warehouse section of the documents.

+1
source

All Articles