I have uploaded an apk (version 1.0) with 22 tables in SQLite Database on Google Playstore.
Now i want to update database with 36 tables in new version (version 2.0) of application.
I am storing
datebase
at default location so when i press "Clear data" in Application Manager, database is gonna deleted.
I just want to know how to delete old database (same as clear data) when user update new version?
If is there any solution for clear data while updating application from play store then also answered me.
Your help would be appreciated.
Thanks.
Finally done with simple solution:
/** UPGRADE DATABASE **/
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
Log.i(TAG, "Database Version: OLD: "+ oldVersion + " = NEW: "+newVersion);
if(context.deleteDatabase(DATABASE_NAME))
Log.i(TAG, "Database Deleted....");
else
Log.i(TAG, "Database Not Deleted..");
}
you can use this method to delete your database.
context.deleteDatabase(DATABASE_NAME);
You can also use this method to find your database path first and then delete that.
File myDb = context.getDatabasePath(DATABSE_NAME);
Boolean isDelete = myDb.delete();
The other solution is , if you want to update your database then just change your version number of database. onUpgrade()
will automatically get called and your old database will be deleted and new database will be created.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With