Search code examples
androidandroid-activityandroid-lifecycleandroid-bundleandroid-savedstate

Cases when savedInstanceState is NOT null


If I do not explicitly call onSaveInstanceState(), which are possibilities, when savedInstanceState is not null in onCreate?

I see one option, when system recreates my app after crash - then savedInstanceState is not null.

Which are other options?


Solution

  • Which are possibilities, when savedInstanceState is not null in onCreate()?

    1. System was on shortage of memory, so it killed the process of your app. User navigates to your app, now onCreate() will be called with non-null Bundle.
    2. After configuration change (e.g. orientation change) - onCreate() will be called with non-null Bundle.

    If I do not explicitly call onSaveInstanceState()

    You shouldn't do that on your own. It's the system that will call activity lifecycle methods and onSavedInstanceState/onRestoreInstanceState.