title: Both Fragment in ActionBar return true for fragment.isVisible()
body: <p>In my <code>MainActivity</code> with <code>ActionBar</code> I listen to a listener from a <code>DialogFragment</code> and based on which Fragment of <code>ActionBar</code> i am on, I need to do some things.</p>
  
  <p>I am using below code to get the current fragment and check which of the two <code>ActionBar</code> fragment i am on:</p>
  
  <pre><code> private Fragment getVisibleFragment() {
      FragmentManager fragmentManager = getSupportFragmentManager();
      List&lt;Fragment&gt; fragments = fragmentManager.getFragments();
      if (fragments != null) {
          for (Fragment fragment : fragments) {
              if (fragment != null &amp;&amp; fragment.isVisible())
                  return fragment;
          }
      }
      return null;
  }
  </code></pre>
  
  <p>but <code>fragment.isVisible()</code> returns true for both the fragments. Why would that be? Is there another flag I need to consider?</p>
  
  <p>Below is my <code>FragmentPagerAdapter</code> implentation:</p>
  
  <pre><code>public class SectionsPagerAdapter extends FragmentPagerAdapter {
  Context context;
  public SectionsPagerAdapter(FragmentManager fm, Context context) {
      super(fm);
      this.context = context;
  }
  
  @Override
  public Fragment getItem(int index) {
      switch (index) {
          case 0:
              return new ReceivedListFragment();
          case 1:
              return new SentListFragment();
      }
      return null;
  }
  
  @Override
  public int getCount() {
      // Show 2 total pages.
      return 2;
  }
  
  @Override
  public CharSequence getPageTitle(int position) {
      Locale l = Locale.getDefault();
      switch (position) {
          case 0:
              return context.getString(R.string.title_section1).toUpperCase(l);
          case 1:
              return context.getString(R.string.title_section2).toUpperCase(l);
      }
      return null;
  }
  }
  </code></pre>