1

In a course, I learned that onSaveInstanceState() is necessary to get the variable values before onDestroy() is called, but according to What exactly does onDestroy() destroy? the variables are not actually cleared.

So my question is, what is the use of the onSaveInstanceState(), if the variables are saved anyways?

Community
  • 1
  • 1
StoneMan
  • 423
  • 3
  • 18

1 Answers1

2

onSaveInstanceState is always called when another Activity comes to the foreground. And so is onStop.

However, onRestoreInstanceState was called only when onCreate and onStart were also called. And, onCreate and onStart were NOT always called.

So it seems like Android doesn't always delete the state information even if the Activity moves to the background. However, it calls the lifecycle methods to save state just to be safe. Thus, if the state is not deleted, then Android doesn't call the lifecycle methods to restore state as they are not needed.

please refer this link for more information

http://developer.android.com/guide/components/activities.html#SavingActivityState

Sam
  • 4,046
  • 8
  • 31
  • 47
  • I understand, thanks, so when's an instance where Android DOES call the restore/save state methods? – StoneMan Jul 31 '14 at 06:17