title: FragmentPagerAdapter - How to handle Orientation Changes?
body: <p>I use a <code>FragmentPagerAdapter</code> containing several Fragments that need to be notified about changes to the <code>database</code>. I  do this by iterating over the fragments, which implement a callback interface, and calling a <code>refreshData()</code> method. </p>
  
  <p>This works just fine until the device changes orientation. After an orientation change, the fragment UI does not visibly refresh even though the method call seems to work.</p>
  
  <p>From what I have read so far this occurs because the <code>FragmentPagerAdapter</code> handles the fragment life-cycle and the fragments that receive the callback are not the ones that are actually displayed. </p>
  
  <pre><code>private class DataPagerAdapter extends FragmentPagerAdapter {
  
      private DataFragment[] fragments = new DataFragment[] {
                                       new FooDataFragment(), BarDataFragment()};
  
      public DataPagerAdapter(android.support.v4.app.FragmentManager fm) {
          super(fm);
      }
  
      @Override
      public Fragment getItem(int position) {
          return fragments[position];
      }
  
      @Override
      public int getCount() {
          return fragments.length;
      }
  
      public DataFragment[] getFragments() {
          return fragments;
      }
  }
  
  protected void refreshData() {
      for (DataFragment dataFragment : mPagerAdapter.getFragments()) {
       dataFragment.refreshData();
  }
  </code></pre>
  
  <p>I temporarily fixed this issue using a broadcast receiver inside each fragment, but this solution seems to be wasteful and might create memory leaks. How to I fix this properly? I use a different layout and logic in landscape mode so I want to use the newly created fragments after an orientation change.</p>