I need to update user information everytime the user after working with the Android App closes the App.How can do the same. do i have some onDestroy kind of method in Application that i can use for the same. Kindly update. thanks
Asked
Active
Viewed 113 times
0
-
1please check this answer : http://stackoverflow.com/a/17278496/957654 – Dec 28 '14 at 06:59
-
Not very helpful .the link does not offer any solution to this problem. – user2779311 Jan 01 '15 at 09:06
1 Answers
0
There absolutely is such a method - and you guessed it's name correctly. You could override the onDestroy()
method.
However, onDestroy()
is also called with the application is rotated. There are other issues as well.
Android doesn't really have a concept of closing the app. The best way to do this is to save onPause()
- which will be basically every time the user leaves the app for some reason, such as for multitasking. Just override the onPause()
method and go from there:
@Override
protected void onPause() {
super.onPause();
saveData()
}
private void saveData() {
//do whatever to save data here
}
I would also read about the android application lifecycle to find out more about how all of this works.

Alex K
- 8,269
- 9
- 39
- 57
-
My app has a no of activities .if i write saveData in onPause in one of the activity then as soon as i shift to another activity it will be called which is not desirable.only when the user exits all activities is when i want to saveData – user2779311 Dec 28 '14 at 07:10
-