title: Viewpager - setCurrentItem(1), the fragment parent fragment doesn't get onActivityResult() when child fragment calls startActivityForResult
body: <p>So I have a nested Fragment and view pager scenario. I have an activity that loads ParentFragment. ParentFragment has a ViewPager that has 4 fragments. Normally the view pager starts at 0. But because I want to help the user return back to their previous position, I wanted to see what happens if I use setCurrentItem(1) for example.</p>
  
  <p>The viewpager does go to the 2nd tab when I call setCurrentItem(1), however, if the user triggers the onClickListener to startActivityForResult from the MyFrag2, the onActivityResult on the ParentFragment does NOT get called. However, if I use setCurrentItem(0) or don't ever call that so the view pager starts off at the first position every time, then the ParentFragment gets the onActivityResult() call which then passes it to the underlying fragments.</p>
  
  <p>I thought originally the ParentFragment was cached or the Fragments in the ViewPager were cached, but I couldn't find information supporting that. Any help?</p>
  
  <p>Here is the MainActivity</p>
  
  <pre><code>public class MainActivity extends FragmentActivity {
      @Override
      public void onActivityResult(int requestCode, int resultCode, Intent data) {
          super.onActivityResult(requestCode, resultCode, data);
      }
  }
  </code></pre>
  
  <p>The following is the parent fragment</p>
  
  <pre><code>public class ParentFragment extends Fragment {
      ViewPager viewPager;
      ArrayList&lt;Fragment&gt; listOfFrags = new ArrayList&lt;Fragment&gt;();
  
      // other code here
  
      @Override
      public void onActivityCreated(Bundle savedInstanceState) {
          super.onActivityCreated(savedInstanceState);
          initViewPager()
      }
  
      public void initViewPager() {
          Fragment frag1 = MyFrag1.newInstance();
          Fragment frag2 = MyFrag2.newInstance();
          Fragment frag3 = MyFrag3.newInstance();
          Fragment frag4 = MyFrag4.newInstance();
          listOfFrags.add(frag1);
          listOfFrags.add(frag2);
          listOfFrags.add(frag3);
          listOfFrags.add(frag4);
  
          PagerAdapter pagerAdapter = MyPagerAdapter(getChildFragmentManager(), listOfFrags);
          viewPager.setAdapter(pagerAdapter);
  
          // proving a point here that setting something other than 0 causes weird behaviour
          viewPager.setCurrentItem(1);
      }
  
      @Override
      public void onActivityResult(int requestCode, int resultCode, Intent data) {
          super.onActivityResult(requestCode, resultCode, data);
  
          for (Fragment frag : listOfFrags) {
              frag.onActivityResult(requestCode, resultCode, data);
          }
      }
  }
  </code></pre>
  
  <p>Here is the the MyFrag2</p>
  
  <pre><code>public class MyFrag2 extends Fragment {
  
      public onClickListener getButtonClickListener() {
          return new View.OnClickListener() {
                  @Override
                  public void onClick(View v) {
                      Intent intent = new Intent(getContext(), OtherAcivity.class);
                      startActivityForResult(intent);
                  }
          });
      }
  
      @Override
      public void onActivityResult(int requestCode, int resultCode, Intent data) {
          super.onActivityResult(requestCode, resultCode, data);
  
          // do stuff
      }
  }
  </code></pre>