title: Android Fragment - saveFragmentInstanceState() and setInitialSavedState() not working between activities
body: <p>I have a fragment that contains a spinner and I need to re-use the fragment across two activities so that the selection status of the spinner persists.</p>
  
  <p>I have used the suggestion from <a href="https://stackoverflow.com/a/12465343/1617737">this SO answer</a> to implement <code>saveFragmentInstanceState()</code> and <code>setInitialSavedState()</code> in the following manner:</p>
  
  <ol>
  <li>On activity A, the user selects a spinner item</li>
  <li><code>saveFragmentInstanceState()</code> is called on activity A's spinnerFragment</li>
  <li>Activity B is then started</li>
  <li><code>setInitialSavedState()</code> is called on activity B's spinnerFragment</li>
  <li>Activity B <strong>should</strong> be shown with the same selected spinner value as before...</li>
  </ol>
  
  <p>...but this doesn't happen as, in activity B, the selected spinner value is not remembered.</p>
  
  <p>My code is below. Can anyone see what the problem might be? Or am I not using the correct approach?</p>
  
  <p><strong>SpinnerFragment - code executed when a spinner item is selected...</strong></p>
  
  <pre><code>Intent activityBIntent = new Intent(getActivity(), ActivityB.class);
  android.app.FragmentManager fm = getActivity().getFragmentManager();
  SavedState spinnerFragmentState = fm.saveFragmentInstanceState(SpinnerFragment.this);
  activityBIntent.putExtra(ActivityB.FRAGMENT_STATE_KEY, spinnerFragmentState);
  startActivity(activityBIntent);
  </code></pre>
  
  <p><strong>Activity B - code executed in onCreate()...</strong></p>
  
  <pre><code>    setContentView(R.layout.activity_b);
  
      /*
       * Create fragmentContainer
       */
      SpinnerFragment spinnerFragment = new SpinnerFragment();
      SavedState spinnerFragmentState = getIntent().getParcelableExtra(FRAGMENT_STATE_KEY);
      Log.d(LOG_TAG, "spinnerFragmentState: " + spinnerFragmentState); //this isn't null
      spinnerFragment.setInitialSavedState(spinnerFragmentState);
  
      /*
       * Add spinnerFragmentContainer to layout
       */
      android.app.FragmentManager fragmentManager = getFragmentManager();
      FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
      fragmentTransaction.add(R.id.spinnerFragmentContainer, spinnerFragment);
      fragmentTransaction.commit();
  </code></pre>
  
  <p>PS - Unlike this question, the other questions/answers I have found on this topic do not refer to persisting fragment state between different activities.</p>