title: maintain Item selection on orientation change
body: <p>I am trying to restore the state of the action mode on orientation change. But it does not work properly. Following the below sequence of steps, in #3 and #4 the selections get corrupted :</p>
  
  <ol>
  <li>Long click an item - item is highlighted, contextual action bar shows with title shows "1 selected". Looks good.</li>
  <li>Turn the phone to landscape - no change. Looks good.</li>
  <li>Turn the phone back to portrait - item is not highlighted, contextual action bar is gone</li>
  <li>Long click an item - item is highlighted, contextual action bar shows with title shows "0 selected"</li>
  </ol>
  
  <p><code>myListView.getCheckedItemCount()</code> in <code>onSaveInstanceState()</code> returns 0 on #3. That's where the problem starts.</p>
  
  <p>What am i doing wrong in my fragment(using support library)?</p>
  
  <pre><code>@Override
  public void onSaveInstanceState(Bundle outState) {
      //check if any items are selected
      if (myListView.getCheckedItemCount() &gt; 0) {
          //get the list of selected items and convert it to an int Array
          //because SparseBooleanArray cannot be stored in a bundle
          SparseBooleanArray selectedItems = myListView.getCheckedItemPositions();
          int[] selectedItems_intArray = new int[myListView.getCheckedItemCount()];
          for (int i = 0; i &lt; selectedItems.size(); i++) {
              if (selectedItems.valueAt(i) == false)
                  continue;
              selectedItems_intArray[i] = selectedItems.keyAt(i);
          }
          outState.putIntArray(KEY_CHECKED_ITEMS, selectedItems_intArray);
      }
  }
  
  @Override
  public void onViewStateRestored(Bundle savedInstanceState) {
      super.onViewStateRestored(savedInstanceState);
      if (savedInstanceState != null) {
          int[] checkedItems = savedInstanceState.getIntArray(KEY_CHECKED_ITEMS);
          if (checkedItems != null) {
              actionMode = ((ActionBarActivity) getActivity()).startSupportActionMode(new ContextualActionBarActionModeCallBack());
  
              for (int i = 0; i &lt; checkedItems.length; i++) {
                  myListView.setItemChecked(checkedItems[i], true);
              }
  
              actionMode.setTitle(myListView.getCheckedItemCount() + " selected");
          }
      }
  }
  
  @Override
  public void onActivityCreated(Bundle savedInstanceState) {
      super.onActivityCreated(savedInstanceState);
      myListView = (ListView) getActivity().findViewById(R.id.myListView);
      adpt = new myCustomCursorAdapter(getActivity());
      myListView.setAdapter(adpt);
      //Choice mode is allowed only after a long click
      //disabling it on first time load
      myListView.setChoiceMode(ListView.CHOICE_MODE_NONE);
          myListView.setOnItemLongClickListener(new OnItemLongClickListener(){
          @Override
          public boolean onItemLongClick(AdapterView&lt;?&gt; parent, View view, int position, long id){
              if(actionMode == null){
                  //Start the action mode
                  actionMode = ((ActionBarActivity)getActivity()).startSupportActionMode(new ContextualActionBarActionModeCallBack());
  
                  myLisVIew.setItemChecked(position, true);                           
                  actionMode.setTitle(myListView.getCheckedItemCount() + " selected");
                  return true;
                  }
              else return false;
          }
      });
  }
  
  @Override
  public void onResume(){
      super.onResume();
      getLoaderManager().initLoader(0,null,this);
  }
  
  private class ContextualActionBarActionModeCallBack implements ActionMode.Callback{
      @Override
      public boolean onCreateActionMode(ActionMode mode, Menu menu) {
          MenuInflater inflater = mode.getMenuInflater();
          inflater.inflate(R.menu.mycontextmenu, menu);   
          myListView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
      }
      ...
      ...
  }
  </code></pre>
  
  <p><strong>ListView layout element :</strong></p>
  
  <pre><code>&lt;ListView
          android:id="@+id/myListView"
          android:layout_height="match_parent"
          android:layout_width="match_parent"
          android:layout_alignParentTop="true"
          android:listSelector="@android:color/transparent"
          android:stackFromBottom="true"
          android:layout_above="@id/layout_input"
          android:divider="#00000000"
          /&gt;
  </code></pre>