1

Let's say I'm pushing a new version app to google play (17 to 18).

Is there a chance some devices have SharedPreference wiped out ? How about the local database ?

I think it could happen if some device somehow where to uninstall reinstall the app automatically rather than update.

Note : I've actually seen SharedPreferences getting wiped out on a few devices after update. Which is why I wonder why, how and it can happen to the Database as well.

Sebastien FERRAND
  • 2,110
  • 2
  • 30
  • 62
  • if it is an uninstall all the data will be deleted no matter even if the data is stored in a database – Sony Feb 08 '18 at 07:54
  • 3
    I have not seen this happen except when you do database changes without a migration therefore causing inconsistency; that will require a fresh install and that also implies everything is wiped out; – Eenvincible Feb 08 '18 at 07:54

1 Answers1

1

in your SQLiteOpenHelper

    @Override
    public void onUpgrade(final SQLiteDatabase db, final int oldVersion, final int newVersion) {
      if (oldVersion < newVersion) {
        final Cursor cursor = db.rawQuery("select name from sqlite_master", null);
        if (cursor != null) {
          while (cursor.moveToNext()) {
            db.execSQL("delete from " + cursor.getString(0));
          }
          cursor.close();
        }
      }
    }
sanemars
  • 767
  • 5
  • 18