I am making an app in which i need that the rows that were inserted in the tables should get deleted on click of a button when the activity restarts.
I have tried the following approaches but didnot get the desired result and the same rows get inserted again.
public void deleteDatabase(String databaseName) {
context.deleteDatabase(databaseName);
}
and
public void deleteAll(){
db.execSQL("TRUNCATE TABLE" +DATABASE_TABLE);
db.execSQL("TRUNCATE TABLE" +DATABASE_TABLE_ICOn);
db.execSQL("TRUNCATE TABLE" +DATABASE_TABLE_NAVIGATION);
this.db.delete(DATABASE_TABLE, null, null);
this.db.delete(DATABASE_TABLE_NAVIGATION,null, null);
this.db.delete(DATABASE_TABLE_ICOn, null, null);
}
db = new WineDatabaseAdapter(HomePageWithPhoneIsOfflineDialog.this);
final AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage("Your Phone is Offline")
.setCancelable(false)
.setPositiveButton("Go Online",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog1, int id1) {
if(WineDatabaseHelper.checkDataBase()==true){
db.deleteDatabase(WineDatabaseHelper.DATABASE_NAME);
//db.deleteAll();
}
What shall i do to solve my problem.
Thanks
Truncate is not supported by Sqlite so its better to use DELETE
DELETE FROM MyTable
You can also execute VACUUM to compact the database when you are deleting lot of data and want to shrink the database file.