سؤال

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

هل كانت مفيدة؟

المحلول

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.

نصائح أخرى

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.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top