I have an application which only supports portrait mode. I’m passing all my arguments using serialization, passing by means of intents – intent.putExtra() ant then in onCreate() – getIntent().getExtras().getX(MY_PARAM_NAME)…
This works even when the system shuts down the VM, because of crashes related to other things. The activities seem to be started again with the correct parameters thanks to serialization.
So the question is, is save instance state necessary in my case? It seems to work well without it… didn’t get any problems yet. But maybe I’m missing something, or didn’t test enough.
As you’ve pointed out, if your
Activitygets killed off (i.e. due to low resources), when it is recreated, it is passed the originalIntentthat started it. In your case, that means you get your serialized objects back.Overriding
onSaveInstanceStateis important for the scenario where something has changed during the execution of yourActivity(that hasn’t been persisted elsewhere) that you would like to maintain in case it gets killed off.For example, storing member variables in your
Activityis dangerous for when theActivityis killed and recreated, unless you store them in theBundleinonSaveInstanceState, and then restore them from theBundlepassed toonCreate.Update: A great way to test the need for implementing that method is to force Android to kill your activities as soon as you leave them. Then, run your app and see if there are any problems. You can do this with the Dev Tools App on an emulator, or in ICS by going to Settings -> Developer options, and checking “Don’t keep activities”.