I have a little app and want to save some data when exiting the application. I intended to do this in a method, which I call when the application is exited. I guess I could write in the necessary code in the onDestroy()
of every possible activity. But is there a more efficient way that I only have to write the code once and it counts for every activity or for the entire application?
Asked
Active
Viewed 32 times
0

Zonico
- 192
- 1
- 11
-
https://stackoverflow.com/questions/17278201/android-ondestroy-or-similar-method-in-application-class – Daniel Nugent Aug 07 '17 at 18:16
-
what do you mean with "when the application is exited"? – lelloman Aug 07 '17 at 18:47
1 Answers
0
It is possible to get a callback when your application goes to background. Implement the onTrimMemory
method in your Application
class and check for TRIM_MEMORY_UI_HIDDEN
level.
@Override
public void onTrimMemory(int level) {
super.onTrimMemory(level);
if (level == TRIM_MEMORY_UI_HIDDEN) {
// your app went to background now.
}
}

Bob
- 13,447
- 7
- 35
- 45