HavenB3
HavenB3

Reputation: 129

How can I ensure that my app's data doesn't get deleted when releasing an update?

My android app saves an array of Objects to cache using serializable, but when updates are released, the array is completely deleted and users have to re-do all input. What is the solution to this? Thanks in advance

Upvotes: 0

Views: 72

Answers (2)

alijandro
alijandro

Reputation: 12147

How did you store you serializable object to the cache? The package management system will keep the old data for an update installation of the app.

    ObjectOutputStream objectOutputStream = null;
    try {
        objectOutputStream = new ObjectOutputStream(new FileOutputStream(
                getCacheDir() + File.separator + "object"));
        MyObject object = new MyObject();
        object.setData(15);
        object.setName("name");
        objectOutputStream.writeObject(new MyObject());
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } finally {
        if (objectOutputStream != null) {
            try {
                objectOutputStream.close();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
    }

Upvotes: 1

CodyEngel
CodyEngel

Reputation: 1501

Look into ActiveAndroid if you are fine with storing data on the device. Look into building out a restful API in the cloud if you want it to persist forever.

Upvotes: 0

Related Questions