Android app keeps losing data when users upgrade

Viewed 47

I've been running an Android app for 10 years now, and it seems like every time we release a new build to production through Google Play we get contacted by a little flurry of users saying that it has lost all of their data, and they are reset back to the beginning.

It seems to affect a range of users. Many of them are using phones that support external storage, but it doesn't seem to matter whether they had the app installed there or in internal storage (in our AndroidManifest.xml we have android:installLocation="auto"). I can't identify any consistent pattern about Android versions etc. I also cannot reproduce it myself, even by installing the old APK prior to the issue and then upgrading to the latest APK.

We use SQLite via the android.database.sqlite package / SQLiteOpenHelper with GreenDAO on top of that:

DBHelper helper = new DBHelper(context);
SQLiteDatabase db = helper.getWritableDatabase();

I got affected user to send screenshots of the App settings from Android. It still reports 11.55 Mb of "User data" - so I feel like the data is hiding there somewhere? But for whatever reason it's like they've been given a new database.

Has anybody ever experienced anything like this? How can I diagnose the cause? I don't know how SQLiteOpenHelper determines the filename for the database? Are there any third party apps that would let them browse the filesystem to see what database files exist?

1 Answers

My guess is that you guys change database schema without actually migrating the user data to the new schema. I can't tell for sure without seeing your DB code, but you should have 2 functions: onCreate() and onUpgrade() that manage the schema, and my guess is that somewhere in there, you're either dropping tables or creating new ones instead of migrating gracefully from the old version to the new one.

Here's a basic write-up on how migrations should be handled

Edit: Since this doesn't seem to be the case, the only other thing I can think of is if you find a user with a rooted phone that this is happening to, and have them explore the file system to find your actual DB. Maybe they can send you the file, or they can explore it directly on their device using SQLite Manager

Related