title: Nested Fragment with backstack Resume
body: <p>In my application there are several <code>fragment</code>s in an <code>activity</code> and I am maintaining a <code>backStack</code> for these <code>fragment</code>. Everything is okay, but there is a nested fragment among them. When I put it into <code>backStack</code> and again resume in by pressing back button, the fragment looks overllaping previous content (child fragment). 
  This is the normal view:</p>
  
  <p><img src="https://i.stack.imgur.com/xt3d8.png" alt="enter image description here"></p>
  
  <p>This is the screenshot of overlapping view (when I resume the fragment):</p>
  
  <p><img src="https://i.stack.imgur.com/LIKX3.png" alt="enter image description here"></p>
  
  <p>You can get the difference as the second one's text is more deep (that means child fragment is overlapping)</p>
  
  <p>How can I avoid that? This the code for my nested fragment:</p>
  
  <pre><code>public class CompetitiveProgramming extends SherlockProgressFragment implements
          OnChapterSelectListener, OnSubChapterSelectListener {
  
      View mContentView;
      static public List&lt;Chapter&gt; chapterList = new ArrayList&lt;Chapter&gt;();
      private ProcessTask processTask = null;
  
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          this.setRetainInstance(true);
      }
  
      @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container,
              Bundle savedInstanceState) {
          mContentView = inflater.inflate(
                  R.layout.competitive_programming_exercise, container, false);
          return super.onCreateView(inflater, container, savedInstanceState);
      }
  
      @Override
      public void onActivityCreated(Bundle savedInstanceState) {
          super.onActivityCreated(savedInstanceState);
          setContentShown(false);
          setContentView(mContentView);
          processTask = new ProcessTask();
          processTask.execute();
      }
  
  
      protected class ProcessTask extends AsyncTask&lt;Void, Void, Void&gt; {
  
          @Override
          protected Void doInBackground(Void... params) {
              // background task
              return null;
          }
  
          @Override
          protected void onPostExecute(Void result) {
              super.onPostExecute(result);
              FragmentTransaction transaction = getChildFragmentManager()
                      .beginTransaction();
              if (mContentView.findViewById(R.id.fragment_container) != null) {
                  getChildFragmentManager().beginTransaction()
                          .add(R.id.fragment_container, new ChaptersListFragment()).commit();
              } else {
                  transaction.add(R.id.category_fragment, new ChaptersListFragment());
                  transaction.add(R.id.sub_category_fragment, new SubChaptersListFragment());
                  transaction.add(R.id.sub_sub_category_fragment,
                          new SubSubChaptersListFragment());
              }
              transaction.commit();
              setContentShown(true);
          }
  
      }
  
      static protected class Chapter {
          String chapterTitle;
          List&lt;SubChapter&gt; subchapterList;
  
          public Chapter(String chapterTitle, List&lt;SubChapter&gt; subchapterList) {
              this.chapterTitle = chapterTitle;
              this.subchapterList = subchapterList;
          }
  
      }
  
      @Override
      public void onChapterSelected(int position) {
          SubChaptersListFragment subChaptersListFrag = (SubChaptersListFragment) getChildFragmentManager()
                  .findFragmentById(R.id.sub_category_fragment);
          if (subChaptersListFrag != null) {
              subChaptersListFrag.updateList(position);
          } else {
              SubChaptersListFragment subChapterFragment = new SubChaptersListFragment();
              Bundle args = new Bundle();
              args.putInt(SubChaptersListFragment.CHAPTER_POSITION, position);
              subChapterFragment.setArguments(args);
              FragmentTransaction transaction = getChildFragmentManager()
                      .beginTransaction();
              transaction.replace(R.id.fragment_container, subChapterFragment);
  //          transaction.addToBackStack(null);
              transaction.commit();
          }
      }
  
      @Override
      public void onSubChapterSelected(int prev, int position) {
          SubSubChaptersListFragment subSubChaptersListFrag = (SubSubChaptersListFragment) getChildFragmentManager()
                  .findFragmentById(R.id.sub_sub_category_fragment);
          if (subSubChaptersListFrag != null) {
              subSubChaptersListFrag.updateList(prev, position);
          } else {
              SubSubChaptersListFragment subSubChapterFragment = new SubSubChaptersListFragment();
              Bundle args = new Bundle();
              args.putIntArray(SubSubChaptersListFragment.POSITIONS, new int[]{prev, position});
              subSubChapterFragment.setArguments(args);
              FragmentTransaction transaction = getChildFragmentManager()
                      .beginTransaction();
              transaction.replace(R.id.fragment_container, subSubChapterFragment);
  //          transaction.addToBackStack(null);
              transaction.commit();           
          }
      }
  
      @Override
      public void onStop() {
          super.onStop();
          if (processTask != null &amp;&amp; processTask.getStatus() != AsyncTask.Status.FINISHED) {
              processTask.cancel(true);
          }
      }
  
  }
  </code></pre>