I use an insert query in onCreate and I want to delete all that data in onDestroy but I cant make it work, everytime I start the application the data is doubled. It seems that onDestroy is not working.
checkout my codes
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_student_view);
toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
myDbHelper = new DatabaseHelper(this, DATABASE_NAME, null,
DATABASE_VERSION);
sqlHandler = new SQLHandler(this);
mDb = myDbHelper.getWritableDatabase();
String query = "INSERT INTO scholar_table(Name,Top,Continent,Region,Location,Introduction,Alumni) " +
"values ('Wesleyan University Philippines','290','Luzon','Region 3','Nueva Ecija','WUP Intro','WUP Alumni')";
sqlHandler.executeQuery(query);
@Override
public void onDestroy(){
super.onDestroy();
sqlHandler = new SQLHandler(this);
mDb = myDbHelper.getWritableDatabase();
String query = "DELETE * FROM scholar_table";
sqlHandler.executeQuery(query);
finish();
}
Aucun commentaire:
Enregistrer un commentaire