onSaveInstanceState is not saving my values ( onCreate input Bundle is always null )

I got this solve by having:

intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);

when re-launching the old intent that has the saved state from background. Without this flag, I think that when startActivity is called, it creates a new instance of the Activity instead of getting the old one from the stack.


There is nothing wrong with your code. Try rotating the device when on activity A. You will see the following in the Log, which means your onSaveInstanceState() is working fine:

saved instance is nullfalse

Here are an excerpt from the Android Developer Site, which you may find interesting:

The callback method in which you can save information about the current state of your activity is onSaveInstanceState(). The system calls this method before making the activity vulnerable to being destroyed and passes it a Bundle object. The Bundle is where you can store state information about the activity as name-value pairs, using methods such as putString(). Then, if the system kills your activity's process and the user navigates back to your activity, the system passes the Bundle to onCreate() so you can restore the activity state you saved during onSaveInstanceState(). If there is no state information to restore, then the Bundle passed to onCreate() is null.

Note: There's no guarantee that onSaveInstanceState() will be called before your activity is destroyed, because there are cases in which it won't be necessary to save the state (such as when the user leaves your activity using the BACK key, because the user is explicitly closing the activity). If the method is called, it is always called before onStop() and possibly before onPause().


You have to do super.onSaveInstanceState(outState) before adding content to it.