title: Fragment not attached to it's Activity but it should
body: <p>I have a very simple <code>Activity</code>:</p>
  
  <pre><code>public class ActivityLogin extends FragmentActivity {
  
      /**
       *
       */
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
  
          this.setContentView(R.layout.activity_login);
          this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
  
          FragmentManager fragmentManager = this.getSupportFragmentManager();
          FragmentLogin fragment = (FragmentLogin) fragmentManager.findFragmentByTag(EnumFragmentTags.LOGIN.getValue());
  
          if (fragment == null) {
              Log.v("Activity", "Fragment is null");
  
              fragment = new FragmentLogin();
              fragmentManager.beginTransaction().add(R.id.login_layout, fragment, EnumFragmentTags.LOGIN.getValue()).commit();
          } else {
              Log.v("Activity", "Fragment is not null");
          }
      }
  }
  </code></pre>
  
  <p>As you can see i only create my <code>Fragment</code> if it is null. The <code>Fragment</code> does not retain instance: So <code>setRetainInstance(false)</code>. When i do some work in the background and call <code>this.getResources()</code> in my <code>Fragment</code> i always get:</p>
  
  <pre><code>Fragment not attached to Activity
  </code></pre>
  
  <p>after i rotated my device. If i dont rotate everything is fine. If i rotate i get the above error. If i use <code>this.getActivity.getResources()</code> instead i get:</p>
  
  <pre><code>java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.res.Resources android.support.v4.app.FragmentActivity.getResources()'
  </code></pre>
  
  <p>So for some reason the activity does not get attached to the <code>Fragment</code>.</p>
  
  <p><strong>Why?</strong></p>
  
  <p>Do i have to use <code>setRetainInstance(true)</code> on my Fragment to get this working? But i thought doing this would lead into Memory issues...</p>