Better yet would be to create a custom activity that all of your activities inherit from, place the final processing logic in the onDestroy() method of the custom activity and then have all subclasses call super.onDestroy() in their onDestroy() method. Solution 3įirst of all it is possible to detect the home key event in an indirect way as shown in my post about killing an application when the home key is pressed: How to close Android application?Īlso it is possible to determine if an activity is the root activity in its onDestroy() method and then have it call a helper class to perform final processing if it is the root activity. Solution 2ĭo it in the onPause() method which is called as soon as the activity is no more in the foreground. Now only you require to get the application object in your Activity like this MyApp app = (MyApp) getApplication() Īnd you can put this inside every onDestroy() of Activity and from here code handling before closing actions can be achieved. say like public class MyApp extends Īnd inside this put your code that you want to be called anywhere in your app. Your issue can be solved if you use a custom Application class.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |