0

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

user2779311
  • 1,688
  • 4
  • 23
  • 31

1 Answers1

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
  • @user2779311 oh...I see. Then no, there is no way to do this. – Alex K Dec 28 '14 at 11:02