-1

I've noticed that in my application onSaveInstanceState method only runs the first time when the activity is destroyed. It should run every time when is destroyed, isn't that correct? ... I need to modify the data that was saved with the first destruction! ... Does anyone know if this is true or i'm getting some mistake?

Thanks.

blackpanther
  • 10,998
  • 11
  • 48
  • 78
Buntupana
  • 984
  • 1
  • 15
  • 33
  • Its run every time the activity is about to destroy. So for example, if you are calling `finish()` in the current activity, it will be called before that. The same is true if you press the back button. – sjain May 01 '13 at 10:11

2 Answers2

2

use SharedPreferences to save data if you want to save data even after onDestroy()

Pragnani
  • 20,075
  • 6
  • 49
  • 74
1

I think it might be useful to read a little here:
http://developer.android.com/reference/android/app/Activity.html

and especially here:
http://developer.android.com/reference/android/app/Activity.html#onSaveInstanceState(android.os.Bundle)

Here is a quoute: "Note that it is important to save persistent data in onPause() instead of onSaveInstanceState(Bundle) because the latter is not part of the lifecycle callbacks, so will not be called in every situation as described in its documentation."

I Also think this might be of interest: https://stackoverflow.com/a/5166797/1367437

I know that I have not really answered your question but it is not entierly clear what you want to achieve. If you want to persist some application data, you should use sharedPreferences, and store your data to it in onPause.

You would then read the data from your sharedPreferences in onResume to restore your state.

Community
  • 1
  • 1