4
One option is to explore your own life cycle of its main activity. For example, when the "Erase All" device feature is used, in this case the main activity of your application will call the method onDestroy()
which is part of the life cycle of a Activity. Thus, you can enter the action to "remove a Child" within the onDestroy()
. Insert the method into your MainActivity
and take a test using a Toast
. Take an example:
@Override
public void onDestroy() {
super.onDestroy();
Toast.makeText(this,"Aplicação destruída com o onDestroy()",
Toast.LENGTH_SHORT).show();
}
Note: For your purpose, there are other ways to do this, for example using Services.
From what I understand you want the "Erase all" method to be called always before the application ends. Since this is difficult for several questions, why don’t you call this method before the application starts? I mean, if the table is filled in before the application starts inserting data then it should be deleted because it is 'garbage' from the previous use.
– Reginaldo Rigo