0

I have a case where my onRestoreInstanceState() is properly called, but for some reason, the prior onSaveInstanceState() is not.

The situation is that I have an Activity that starts another activity. The device is in portrait at this time. While the other activity is active, the device is rotated. It then finishes, returning to my activity. Since the orientation has changed, my activity is destroyed and recreated. However, I am never getting my onSaveInstanceState() method called before the call to destroy. I see the following:

finish (prior activity) onDestroy (my activity) onCreate onRestoreInstanceState onResume

And then of course, I trip over an NPE and crash.

If I simply rotate while my activity is up, I get the OnSaveInstanceState() call as I expected. Just not when it is switching back to my activity from the other activity.

Is this a known issue or is there something else that I can do to work around this?

BJV
  • 1,133
  • 8
  • 15
  • May help you: http://stackoverflow.com/questions/7320785/onsaveinstancestate-is-not-saving-my-values-oncreate-input-bundle-is-always-nu – mmlooloo Aug 03 '14 at 06:52
  • I believe in my case, the activity is not getting destroyed by a direct user action like "Back" - it is getting destroyed due to an orientation change that occurred while another activity was "on top". When that activity finishes, it destroy's my activity because the orientation is different, then recreates it. I do get my onRestoreInstanceState() method called, just not the onSaveInstanceState() call. – BJV Aug 03 '14 at 17:10

0 Answers0