Search code examples
javaandroidrefactoringondestroy

Android use unique onDestroy for all activities


I have an app with several activities and the action to perform on destruction is actually the same, no matter what the Activity is at that moment (deleting some data and performing a HTTP call).
Is there a way to have all activities share the onDestroy method?

Another solution would be to factorize a method in some other static class and have each Activity invoke it during destruction, but a trait-like behaviour would be actually nicer.


Solution

  • Create an abstract BaseActivity, override the onDestroy, and all your other activities should just extend the BaseActivity?

    Why go with singletons, statics, factories etc if what you are describing is a classic OOP trait? :)