If an activity is stopped then recreated what gets passed into getIntent()

android, android-intent

Solution

I would use onPause() for this reason (from the docs)

Note that it is important to save persistent data in onPause() instead of onSaveInstanceState(Bundle) because the latter is not part of the lifecycle callbacks, so will not be called in every situation as described in its documentation.

Then read it back again in `onCreate()` e.g. from database or some other resource you stored it in.

So depending on how important that boolean value is you will use saving mechanism you want.. for persistent state: http://developer.android.com/reference/android/app/Activity.html#SavingPersistentState

And for UI state such as simple texts, selections use `onSaveInstanceState` like described here: Saving Android Activity state using Save Instance State

As an summary: when process killed boolean = gone if not saved :)

Problem

I pass a boolean to my Activity when I create it via an Intent BundleExtra. Now looking at the activity lifecycle, if my activity gets stopped (`onStop`), then another app needs memory so the app process is killed, then the user navigates to the activity (`onCreate`). Will the last onCreate contain my original boolean I passed? I would assume if I wanted that boolean to be saved I would need to save it in `OnSaveInstanceState`, correct?

Original source

Related problems