I have an Activity that call another one by calling startActivity()
, after some time onSaveInstanceState(Bundle outState)
is called and I set a Boolean valeu to recover on the onCreate(Bundle savedInstanceState)
but when this method is called savedInstanceState
comes null. I've searched the internet for an answer, but didn't find anything for my case.
Here's the onSaveInstanceState
method:
@Override
protected void onSaveInstanceState(Bundle outState) {
outState = new Bundle();
outState.putBoolean(Constants.MAIN_ACTIVITY_STATE_RECREATED, true);
super.onSaveInstanceState(outState);
}
The onCreate
:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
setTitle(R.string.activity_main);
if (savedInstanceState!=null && savedInstanceState.getBoolean(Constants.MAIN_ACTIVITY_STATE_RECREATED, false)){
return;
}
//DO SOME STUFF
}
And here's my AndroidManifest declaration of the Activities:
<activity android:name=".MainActivity"
android:screenOrientation="portrait"
android:configChanges="orientation|keyboardHidden">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
This is the called Activity:
<activity android:name=".PhotoUserActivity"
android:screenOrientation="portrait"
android:configChanges="orientation|keyboardHidden"
android:parentActivityName=".MainActivity">
</activity>
If I remove parentActivityName from the declaration of the second activity and make the "back button" by myself, the onCreate of the first Activity is never called.
Thanks for any help!