I am trying to provide an option in my App for the user to wipe out all data and start afresh. I have tried a few things but none seem to work in the sense that the data is still there. Here is my first attempt:
public void clearDatabase(Context context) {
DatabaseHelper helper = new DatabaseHelper(context);
SQLiteDatabase database = helper.getWritableDatabase();
database.delete(Constants.TRANSACTION_TABLE, null, null); //erases everything in the table.
database.delete(Constants.CUSTOMER_TABLE, null, null);
database.delete(Constants.RETAILER_TABLE, null, null);
database.close();
}
This seems to work, but then the app will crash on restart.
Then I try this one from within the SQliteOpenHelper sub class
public void resetDatabase() {
SQLiteDatabase database = getWritableDatabase();
database.execSQL("DROP TABLE IF EXISTS customer_table");
database.execSQL("DROP TABLE IF EXISTS transaction_table");
database.execSQL("DROP TABLE IF EXISTS retailer_table");
database.execSQL(CREATE_CUSTOMER_TABLE);
database.execSQL(CREATE_TRANSACTION_TABLE);
database.execSQL(CREATE_RETAILER_TABLE);
database.close();
}
This does not crash on restart but the data is still there. The only thing that worked is if I change the version number programmatically. But then when I run the app from the IDE it will have an older version number and the app will not start because the version number on the device is higher than the version number in the code.
What else can I try?