If the action is stopped, then what is passed to getIntent () is recreated

I pass the boolean value of my activity when I create it through Intent BundleExtra. Now, looking at the life cycle, if my activity is stopped ( onStop), then another application needs memory to kill the application process, then the user goes to activity ( onCreate). Will the last onCreate contain my original boolean value that I passed? I would suggest that if I wanted the boolean to be saved, I would need to store it in OnSaveInstanceState, right?

+5
source share
3 answers

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

, onPause() ofSaveInstanceState (Bundle), , , .

onCreate() . - , .

, , , , .. : http://developer.android.com/reference/android/app/Activity.html#SavingPersistentState p >

, , onSaveInstanceState, : Android

: , boolean = , :)

+2

, , - . getIntent() , . , , , saveInstanceState(). , , . . .

+4

. , onPause()

onSaveInstanceState ( Bundle) . , ,

SharedPreferences :

SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
sharedPreferences.edit().putBoolean("hiBoolean", booleanValue).commit();

And extract it to your onCreate:

Boolean hiBoolean = sharedPreferences.getBoolean("hiBoolean", true);
+1
source

All Articles