0

I have an app which the moment the user starts running the app it register a new entry in a database. The thing is that when the user quits I would like to delete this registry in the database. I know doing al these inserts and deletes with JSON, MySQL and PHP but I dont know how to apply these functions when the user quits the application in the normal way. I would like to know if there is a function like public onBackPressed() where it does always the same thing but you can overwrite it.

Thanks

Katherine99
  • 980
  • 4
  • 21
  • 40
  • onBackPressed? refer this may help->http://stackoverflow.com/questions/4969541/override-back-button-in-android – KOTIOS Jun 25 '13 at 08:03

2 Answers2

1

There is a method onDestroy() which is called when user is done with application and resources are freed, you can override it in your activity and do whatever you want in it, if you want a one step previous from onDestroy() it is onStop() which is called when activity goes background etc. You can override it as well.

Onur A.
  • 3,007
  • 3
  • 22
  • 37
  • Then this is what I have: `public void onDestroy(){ new Borrar().execute(); super.onDestroy();` . The asynctask Borrar() should delete from the database but this doest not happen. Am I doing it properly? – Katherine99 Jun 25 '13 at 08:55
  • first add @ Override on above of method header then try to call super.onDestroy() first in the body then call your new Borrar().execute(), if these doesnt work try to use onStop() instead of onDestroy(), again with @ Override annotation, p.s on Windows ctrl+space offer you avaiable methods if you choose these methods from there they simply produce a skeleton code for you . – Onur A. Jun 25 '13 at 13:08
1

use Android's onBackPressed() method and remove the super call and do all your operations and at the last stage, write finish(), this will close your application.

This will work only if your other activities are closed, else it will close the current activity and go to the last activity.

Vedang Jadhav
  • 510
  • 2
  • 11