Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

21
  • 30
    Any chance this works on the phone, but not in the emulator? I cannot seem to get a non-null savedInstanceState. Commented Nov 18, 2009 at 22:39
  • 513
    CAREFUL: you need to call super.onSaveInstanceState(savedInstanceState) before adding your values to the Bundle, or they will get wiped out on that call (Droid X Android 2.2). Commented Apr 13, 2011 at 18:59
  • 131
    Careful: the official documentation states, that you should save important information within the onPause-Method because the onsaveinstance-method is not part of the android lifecycle. developer.android.com/reference/android/app/Activity.html Commented Jun 19, 2012 at 7:40
  • 39
    That fact effectively makes onSaveInstanceState almost useless except just for case of screen orientation changes. In almost all other cases, you can never rely on it and will need to manually save your UI state somewhere else. Or preventing your app from being killed by overriding BACK button behavior. I don't understand why they even implemented it like this in the first place. Totally unintuitive. And you can't have that Bundle the system give you to save things into except in this very particular method. Commented Jul 5, 2013 at 11:25
  • 18
    Note that saving / restoring UI state to / from the Bundle is automatically taken care of for Views that have been assigned ids. From the onSaveInstanceState docs: "The default implementation takes care of most of the UI per-instance state for you by calling onSaveInstanceState() on each view in the hierarchy that has an id, and by saving the id of the currently focused view (all of which is restored by the default implementation of onRestoreInstanceState(Bundle))" Commented Jun 24, 2015 at 23:15