Will savedInstanceState
bundle in onCreate()
method be alive (not null) after Application is being killed? If it would, where this bundle is stored in the system.
5 Answers
If Android kills the process hosting your app, it still maintains the "saved instance state" of all active (non-finished) activities. This data is stored by the ActivityManager
. If the user returns to your application, Android will create a new process for the app, instantiate the Application
instance again and then create an instance of the top activity in the activity stack. It will then call onCreate()
on that activity instance passing it the "saved instance state" that was most recently saved for that activity.
If you reboot your phone, all this data is lost (Android does not save application state across reboots).

- 93,459
- 16
- 209
- 274
-
9Since API 21 the `savedInstanceState` can survive reboots when set to [persistableMode](https://developer.android.com/reference/android/R.attr.html#persistableMode). The `Bundle` will be passed into [onCreate(Bundle, PersistableBundle)](https://developer.android.com/reference/android/app/Activity.html#onCreate(android.os.Bundle%2C%20android.os.PersistableBundle)) as second parameter – passsy Sep 14 '16 at 08:05
-
1as @passsy pointed out there is overloaded new method `onSaveInstanceState' taking `PersistableBundle` as an extra parameter, if you are wondering why your `onSaveInstanceState` is not get called you may be using the new method. – Burak Dede Apr 23 '17 at 22:21
-
Maybe a follow up question. Do the tasks that exist right before you reboot the device survive as well? I think they're but I don't see it documented anywhere. – stdout Mar 09 '20 at 09:04
-
1@stdout No. Tasks do not survive reboot. When you boot your device you will notice the list of recent tasks is empty. – David Wasser Mar 09 '20 at 09:58
No it will not, android app maintain it's state as long as it is running : (foreground and background).
if you are looking for something that can span application's different life-cycle use something like SharedPreferences .
Regarding
if the system kills your application process and the user navigates back to your activity
This only happens when android needs memory and have to kill your activity to free resources and your activity in the activity stack. its documented that it is a convenience way to maintain user experience.
android documentations:
A background activity (an activity that is not visible to the user and has been paused) is no longer critical, so the system may safely kill its process to reclaim memory for other foreground or visible processes. If its process needs to be killed, when the user navigates back to the activity (making it visible on the screen again), its onCreate(android.os.Bundle) method will be called with the savedInstanceState it had previously supplied in onSaveInstanceState(android.os.Bundle)
so that it can restart itself in the same state as the user last left it.
so you should not expect the InstanceState be maintained all of the time. Activity source code at codegrep
Edit
by searching google for android instance state
I came by this resource Android Recreating an Activity
When your activity is destroyed because the user presses Back or the activity finishes itself, the system's concept of that Activity instance is gone forever because the behavior indicates the activity is no longer needed. However, if the system destroys the activity due to system constraints (rather than normal app behavior), then although the actual Activity instance is gone, the system remembers that it existed such that if the user navigates back to it, the system creates a new instance of the activity using a set of saved data that describes the state of the activity when it was destroyed. The saved data that the system uses to restore the previous state is called the "instance state" and is a collection of key-value pairs stored in a Bundle object.
Edit 2 After digging around android internals, it seems like it is all about ActivityManagerNative
Whenever an activity is pausing it's state is passed Using a Parcel Object to the ActivityManager process.
public void activityPaused(IBinder token, Bundle state) throws RemoteException
{
Parcel data = Parcel.obtain();
Parcel reply = Parcel.obtain();
data.writeInterfaceToken(IActivityManager.descriptor);
data.writeStrongBinder(token);
data.writeBundle(state);
mRemote.transact(ACTIVITY_PAUSED_TRANSACTION, data, reply, 0);
reply.readException();
data.recycle();
reply.recycle();
}
And whenever ActivityManagerNative creates an activity, it passes that State back to the activity using Parcel
public boolean onTransact(int code, Parcel data, Parcel reply, int flags)
throws RemoteException {
switch (code) {
case START_ACTIVITY_TRANSACTION:
{
data.enforceInterface(IActivityManager.descriptor);
IBinder b = data.readStrongBinder();
IApplicationThread app = ApplicationThreadNative.asInterface(b);
Intent intent = Intent.CREATOR.createFromParcel(data);
String resolvedType = data.readString();
Uri[] grantedUriPermissions = data.createTypedArray(Uri.CREATOR);
int grantedMode = data.readInt();
IBinder resultTo = data.readStrongBinder();
String resultWho = data.readString();
int requestCode = data.readInt();
boolean onlyIfNeeded = data.readInt() != 0;
boolean debug = data.readInt() != 0;
int result = startActivity(app, intent, resolvedType,
grantedUriPermissions, grantedMode, resultTo, resultWho,
requestCode, onlyIfNeeded, debug);
reply.writeNoException();
reply.writeInt(result);
return true;
}
.....

- 9,192
- 5
- 39
- 51
-
1The documentation is saying: `Then, if the system kills your application process and the user navigates back to your activity, the system recreates the activity and passes the Bundle to both onCreate() and onRestoreInstanceState().` Am I missing something? – Eugene May 30 '13 at 15:44
-
There is also a good explanation the instance state is saved if application is killed.https://www.youtube.com/watch?v=fL6gSd4ugSI&feature=youtube_gdata_player – Eugene Jun 02 '13 at 16:50
-
"When your activity is destroyed because the user presses Back or the activity finishes itself, the system's concept of that Activity instance is gone forever because the behavior indicates the activity is no longer needed." I've been looking for this, thanks! – Lance Toth Feb 20 '18 at 09:46
Following table from one of the Android training materials might be more helpful.
In that, bundle saved by onSavedInstanceState
is valid while the app is OPEN which means the app may be PAUSed or even STOPed and DESTROYed (due to reasons such as rotation) but NOT QUIT using the Back button.
The table also shows other available options if not onSavedInstanceState
.

- 1,354
- 15
- 26
The answers here are little outdated. In 2021, savedInstanceState
is persisted across device reboots as it is written to the disk and will be available in onCreate
when the activity is created again
The Official Doc States
Saved instance state bundles persist through both configuration changes and process death because onSavedInstanceState() serializes data to disk

- 433
- 5
- 9
Android docs do state that savedInstanceState
will survive process death, however, in my tests, it doesn't. You can emulate process death by pressing the red button in the top toolbar
It's possible that the onSaveInstanceState
bundle might not be destroyed when the Android system terminates the process, but it could be destroyed when we manually terminate the process ourselves.
Here is the overview that android doc provides
You can read more here

- 14,435
- 6
- 54
- 69