AggieDev
AggieDev

Reputation: 5045

Why do Android updates of my app erase information?

In my app, I have a list of objects that are stored with a FileOutputStream in the code below. Also, I have any settings in my app stored with SharedPreferences. Whenever I updated my app on the Google Play store for the first time (for those unfamiliar with the process, I upload the new APK), all objects were deleted for anyone using the app, and all settings set to default. Why did it do this and how can I have the objects stored where they don't disappear after update?

public ObjectStorage readListFromFile()
{
    ObjectStorage temp = null;
    String filename = "storefileobj";
    FileInputStream fis;
    try {
        fis = getActivity().openFileInput(filename);
        ObjectInputStream is = new ObjectInputStream(fis);
        temp = (ObjectStorage) is.readObject();
        is.close();
    } catch (FileNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (StreamCorruptedException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (ClassNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    return temp;
}


public void updateStorage()
{

    String filename = "storefileobj";
    FileOutputStream fos;
    try {
        fos = getActivity().openFileOutput(filename, Context.MODE_PRIVATE);
        ObjectOutputStream os = new ObjectOutputStream(fos);
        os.writeObject(mainObjectList);
        os.close();
    } catch (FileNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

}

Upvotes: 2

Views: 125

Answers (1)

David Manpearl
David Manpearl

Reputation: 12656

For normal updates, your users would not have lost these values.

I believe that each of your users who lost their stored SharedPreference and saved file data were forced to delete their old application in order to install the new application from the Play Store. Otherwise, some of your keys or file formats must have changed.

Signature:

You certainly used Android's Signing Your Applications documentation in order to update at the Play Store, but perhaps the users in question were using an app signed with a different signature (such as a Debug Mode signature) that you had delivered to them separately. This could explain why they were forced to uninstall before updating at the Play Store, thus erasing all of the saved information.

Data Format:

Another alternative is that perhaps the Keys used for the SharedPreference values changed OR the file format or class structure for the ObjectStorage changed, making it impossible to read the old values. This would appear to the users as if the old values disappeared. Then, as the users saved values in the new format, your app would continue to work properly for them.

Summary:

One of the following must have happened:

  1. Your users deleted before reinstall. Or,
  2. Your stored data format changed between versions.

Upvotes: 1

Related Questions