title: Android FragmentSupportManager is returning null when called out of Handler
body: <p>I am using a navigation drawer to switch between my fragments and an Handler to notify the current Fragment about changes in my ForegroundService. The handler code is located in the MainActivity class. All fragments are shown in an container with id "main_content" and replace each other.</p>
  
  <p>All is working fine and my Fragments get updated when I start my Activity and Service but after OrientationChange the fragment manager in the Handler says that the current fragment is null. However the navigationDrawer is working and can still determine the currently shown fragment. To determine the current fragment both the drawer and the handler are using the same method:</p>
  
  <pre><code>private Fragment getCurrentFragment() {
      Fragment current = fragmentManager.findFragmentById(R.id.main_content);
      return current;
  }
  </code></pre>
  
  <p>The same code keeps working even after orientation change for the Navigation Drawer functions.</p>
  
  <p>My handler code to update my fragments looks like this:</p>
  
  <pre><code>private class UIHandler extends Handler{
  private AlertDialog alert;
  @Override
  public void handleMessage(Message msg) {
      if (msg.what == UPDATE) {          
              Fragment currentFragment = mfragmentManager.getCurrentFragment();
              if(currentFragment instanceof BaseFragment){
                  ((BaseFragment) currentFragment).notifyUpdateOccured();
              }
          }
      super.handleMessage(msg);
      }
  }
  </code></pre>
  
  <p>Like I said the the above code works before I changed the orientation and afterwards returns null for the current fragment. </p>
  
  <p>Now looking at the fragment manager stored locally in mfragmentManager while debugging after orientation change:</p>
  
  <p>Reference when called from the navigation drawer:</p>
  
  <pre><code>FragmentManager{450c4ce0 in MainActivity{450c4a58}}
  </code></pre>
  
  <p>Reference when called from the Handler:</p>
  
  <pre><code>FragmentManager{450c4ce0 in null}
  </code></pre>
  
  <p>So I assume it has something to do with the reference of the fragmentManager and not with the fragments and the fragment container at all... Even if I call the fragment manager in a new thread the reference stays the same.</p>
  
  <p>I appreciate any help because I have no idea what I can do about it.</p>