title: FragmentStatePagerAdapter Duplicate fragment
body: <p>I'm using nested FragmentStatePagerAdapter on my single activity application. The current layout is:</p>
  
  <pre><code>Activitiy
    - Login Fragment
    - Master Fragment
        - Tab Fragment #1
        - Tab Fragment #2
        - Tab Fragment #3
    - Another Fragment
    - Another Fragment
  </code></pre>
  
  <p>Everytime i switch back from "Another Fragment" into "Master Fragment" the FragmentStatePagerAdapter instante the same item twice for example</p>
  
  <p>First Time: Tab Fragment #1 #2 #3<br>
  Second Time: Tab Fragment #1 #1 #2 #2 #3 #3<br>
  Third Time: Tab Fragment #1 #1 #1 #2 #2 #2 #3 #3 #3.</p>
  
  <p>To move from fragment to fragment i use</p>
  
  <pre><code>getSupportFragmentManager()
      .beginTransaction()
      .replace(android.R.id.content, XXXX.newInstance(query), TAG_XXX)
      .addToBackStack(null)
      .commit();
  </code></pre>
  
  <p>The MasterFragment code:</p>
  
  <pre><code>@Override
  public void onActivityCreated(Bundle savedInstanceState) {
      super.onActivityCreated(savedInstanceState);
      initFragmentAdapter();
  }
  
  private void initFragmentAdapter() {
      final FragmentSimpleAdapter adapter = new FragmentSimpleAdapter(getChildFragmentManager());
  
      adapter.addFragment(
              getString(...),
              "...",
              XXX.class);
      ...
  
      ViewPager viewPager = (ViewPager) getActivity().findViewById(android.R.id.tabcontent);
      viewPager.setAdapter(adapter);
      viewPager.setOffscreenPageLimit(4);
  
      PagerSlidingTabStrip viewTabs = (PagerSlidingTabStrip) getActivity().findViewById(
              android.R.id.tabhost);
      viewTabs.setViewPager(viewPager);
      viewTabs.setOnPageChangeListener(adapter);
  }
      private final class FragmentSimpleAdapter extends FragmentStatePagerAdapter
         implements ViewPager.OnPageChangeListener {
      private final List&lt;String&gt; mTitles = new LinkedList&lt;&gt;();
      private final List&lt;String&gt; mInstances = new LinkedList&lt;&gt;();
      private final List&lt;String&gt; mTag = new LinkedList&lt;&gt;();
      private Map&lt;Integer, String&gt; mFragmentTags;
      private FragmentManager mFragmentManager;
  
      public FragmentSimpleAdapter(FragmentManager fm) {
          super(fm);
          mFragmentManager = fm;
          mFragmentTags = new HashMap&lt;&gt;();
      }
  
      @Override
      public int getCount() {
          return mTitles.size();
      }
  
      @Override
      public CharSequence getPageTitle(int position) {
          return mTitles.get(position);
      }
  
      @Override
      public Fragment getItem(int position) {
          return Fragment.instantiate(getActivity(), mInstances.get(position), null);
      }
  
      @Override
      public Object instantiateItem(ViewGroup container, int position) {
          Object obj = super.instantiateItem(container, position);
          if (obj instanceof Fragment) {
              Fragment f = (Fragment) obj;
              String tag = f.getTag();
              mFragmentTags.put(position, tag);
          }
          return obj;
      }
  
      public Fragment getFragment(int position) {
          String tag = mFragmentTags.get(position);
          if (tag == null) {
              return null;
          }
          return mFragmentManager.findFragmentByTag(tag);
      }
  
      public FragmentSimpleAdapter addFragment(String title, String tag,
                                               Class&lt;? extends Fragment&gt; fragment) {
          mTitles.add(title);
          mTag.add(tag);
          mInstances.add(fragment.getName());
          return this;
      }
  
      @Override
      public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
      }
  
      @Override
      public void onPageSelected(int position) {
              Analytics.sendViewAnalytic(mTag.get(position))
      }
  
      @Override
      public void onPageScrollStateChanged(int state) {
      }
  }
  </code></pre>