title: Android activity and fragment lifecycle issues in case of app minimization
body: <p>I have a fragment with a multi-choice list. I am trying to save instance of the items that are checked in the list currently and restore them in case of app minimization and such.</p>
  
  <p>Steps of testing:</p>
  
  <ol>
  <li>Reach the multi-choice list fragment.</li>
  <li>Check a few list items</li>
  <li>Press the home key to minimize the app.</li>
  <li>Press the multitasking button and choose my app to restore it</li>
  </ol>
  
  <p>Following is the code that i am using:</p>
  
  <pre><code>adapter = new ArrayAdapter&lt;String&gt;(getActivity(),
          android.R.layout.simple_list_item_multiple_choice,
          android.R.id.text1, listToShow);
  list.setAdapter(adapter);
  
  list.setOnItemClickListener(new OnItemClickListener() {
      @Override
      public void onItemClick(AdapterView&lt;?&gt; parent, View view,
                          int position, long id) {
                      mSelectedItems.clear();
                      int count = categoryList.getCheckedItemCount();
  
                      SparseBooleanArray booleanArray = categoryList.getCheckedItemPositions();
  
                      for (int i = 0; i &lt; count; i++) {
                              mSelectedItems.add(booleanArray.keyAt(i));
                      }
  
                  }
              });
  
  
  @Override
  public void onSaveInstanceState(Bundle outState) {
          Log.d("SubcategoryselectionList", "onsavedinstancestate");
          outState.putIntegerArrayList(SELECTED_ITEM, mSelectedItems);
          super.onSaveInstanceState(outState);
      }
  
  @Override
  public void onViewStateRestored(Bundle savedInstanceState) {
      Log.d("SubcategoryselectionList", "onViewStateRestored");
      if (savedInstanceState != null) {
          if (savedInstanceState.getIntegerArrayList(SELECTED_ITEM) != null) {
              Log.d("SubcategoryselectionList", "onViewStateREstored selected items found");
              mSelectedItems = savedInstanceState
                      .getIntegerArrayList(SELECTED_ITEM);
              for (int i = 0; i &lt; mSelectedItems.size(); i++) {
                  categoryList.setItemChecked(mSelectedItems.get(i), true);
              }
          }
  
      }
      super.onViewStateRestored(savedInstanceState);
  }
  </code></pre>
  
  <p>And when I see the logs, the method <code>onViewStateRestored</code> is never called.</p>
  
  <p>To counter this I thought of using the activity lifecycle and use its method <code>onRestoreInstanceState()</code> to achieve the above mentioned effect but surprisingly I cant see the logs that I added to this method. </p>
  
  <p>Please someone help in clarifying how the lifecycle of the Activity and Fragment working in this case and how can I restore my state in the best possible manner.</p>