OnCreate (Bundle savedInstanceState) is always always null

I know this question was asked earlier in stackoverflow, but the answers did not work for me.

Perhaps worth mentioning:

  • I am using ActionBarSherlock with a support package.
  • Method onSaveInstanceStateCalled when the home button is pressed. The method onCreatealways always gives NULL for Bundle savedInstanceState.
  • The method is onRestoreInstanceStatenever called at all. (I would not mind if I onCreateworked;)).
  • Also (it shouldn't matter) I tried to put it super.onSaveInstanceState(outState)below onSaveInstanceState. Bad luck.

Here is the code. I hope someone had this problem and it was resolved.

public class MainActivity extends SherlockFragmentActivity {

    private static final String LOG_TAG = MainActivity.class.getSimpleName();

    private static String STATE_TO_STORE = "state_to_store";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);        

        Log.d(LOG_TAG, "onCreate: savedInstanceState = " + (savedInstanceState == null ? "NULL" : "Not NULL"));

        // ... more code...
    }

    @Override
    public void onRestoreInstanceState(Bundle savedInstanceState) {
        super.onRestoreInstanceState(savedInstanceState);

        Log.d(LOG_TAG, "onRestoreInstanceState: savedInstanceState = " + (savedInstanceState == null ? "NULL" : "Not NULL"));
    }

    @Override
    public void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);

        outState.putInt(STATE_TO_STORE, 5); // store some int

        Log.d(LOG_TAG, "onSaveInstanceState bundle: " + outState.toString());
    }

    // ... more code ...

}

The log clearly states what onSaveInstanceStateis being called, and onCreate gets savedInstanceState = NULL.

+5
4

, : noHistory = "true".

, .

+11

, , .

, AndroidManifest.xml, "", " " "" .

@style/Theme.AppCompat.Light.DarkActionBar

.

P.S.: , , , .

+4

HOME, . , onCreate , . , , android:finishOnTaskLaunch="true" .

+3

onRestoreInstanceState ( onCreate) , - , . ( ) onRestoreInstanceState. , onSaveInstanceState , onRestoreInstanceState , . , , .

. , .

onRestoreInstanceState?

+2

All Articles