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?
I pass a boolean to my Activity when I create it via an Intent
Share
I would use onPause() for this reason (from the docs)
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
onSaveInstanceStatelike described here: Saving Android Activity state using Save Instance StateAs an summary: when process killed boolean = gone if not saved 🙂