Reputation: 97
I am trying to understand why a very small percentage of users of my Android app report that data stored in internal storage has disappeared, after updating the app.
In my Android app, objects are created with variables selected by the user, and these are stored as data files in internal storage.
Everything works well and as it should. Occasionally when I update the app, a very small percentage of users report that their data has disappeared.
All updates are via Google Play. I have never experienced this problem myself (I check the app with physical devices on an internal test track, and I am unable to duplicate it.
Needless to say, this is a major problem for the affected users.
I have spent a lot of time investigating but I am unable to find a cause for this.
What could cause the data to sometimes disappear when the app is updated from Google Play?
The data is stored with this method:
public static void writeObject(Context context, String filename, Object object) throws IOException {
String tempFile = null;
File dir = context.getDir(dirName, Context.MODE_PRIVATE);
File file = new File(dir, filename);
FileOutputStream fos = new FileOutputStream(file);
ObjectOutputStream oos = new ObjectOutputStream(fos);
oos.writeObject(object);
oos.close();
fos.close();
}
The data is retrieved with this method:
public static PatternObject readObject(Context context, String filename) throws IOException, ClassNotFoundException {
File dir = context.getDir(dirName, Context.MODE_PRIVATE);
File file = new File(dir, filename);
FileInputStream fis = new FileInputStream(file);
ObjectInputStream ois = new ObjectInputStream(fis);
PatternObject patternObject = (PatternObject) ois.readObject();
ois.close();
fis.close();
return patternObject;
}
public static String[] ShowSavedFiles(Context context){
File dir = context.getDir(dirName, Context.MODE_PRIVATE);
String[] SavedFiles;
List<String> list = new ArrayList<>();
File [] fileList = dir.listFiles();
for (File file : fileList){
list.add(file.getName());
}
SavedFiles = list.toArray(new String[0]);
return SavedFiles;
}
Like I say, the code is working fine, and most users, including myself do not experience any problems.
As I understand it, the app update will never remove data files from internal storage. However some users are reporting this problem.
The users with this problem deny uninstalling the app.
One user reported that she had used 'Force Stop' at some point, I have tried that myself but app data is still found.
Upvotes: 2
Views: 138