Android – delete sqlite database when updating new version of application

androidandroid-sqlitedatabasesqlite

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?

Update:

If is there any solution for clear data while updating application from play store then also answered me.

Your help would be appreciated.

Thanks.

Best Answer

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.