title: White screen after going back through Fragments
body: <p>I've got an Android application which is working fine, but I've found an annoying bug which I don't know what else do to solve it.</p>
  
  <p>My application has a single Activity (call it HomeActivity; well, plus the Preferences Activity) and lots of Fragments. HomeActivity manages the replacement of every Fragment using this method (found in this <a href="https://stackoverflow.com/questions/18305945/how-to-resume-fragment-from-backstack-if-exists">thread</a> and especially looking into the following <a href="https://stackoverflow.com/a/18306258/828551">comment</a>):</p>
  
  <pre><code>public void switchFragment(Fragment pFragment, String pTagFragment){
  
      String backStateName = pTagFragment;
      boolean fragmentPopped = mFragmentManager.popBackStackImmediate (backStateName, 0);
  
      if (!fragmentPopped){ //fragment not in back stack, create it.
          FragmentTransaction ft = mFragmentManager.beginTransaction();
          ft.replace(R.id.content_frame, pFragment);
          ft.addToBackStack(backStateName);
          ft.commit();
      }
  
  }
  </code></pre>
  
  <p>To replace a Fragment, what I do is the following:</p>
  
  <pre><code>switchFragment(new FragmentEuskalmet(), FragmentEuskalmet.FRAGMENT_NAME);
  </code></pre>
  
  <p>Here it's the problem: I navigate through several Fragments (say, 3 of them). Then, I wanna go back, so I press back 2 times. When I arrive to the last within the stack, a white screen is shown (i.e. white is shown in the place where the Fragment should be). The odd thing is that if I do a long press to my home button to show the recent apps and I choose again my application, the fragment gets loaded correctly.</p>
  
  <p>I assume there might be something within my <code>switchFragment</code> method, e.g. it may be any issue related to the backStack. One important detail is that I've got written the so called empty constructor in every Fragment.</p>
  
  <p>Can anybody lend me a hand? I can provide further code pieces if anybody request them.</p>
  
  <p><strong>Edit:</strong>
  I've considered compulsory to type my sss method:</p>
  
  <pre><code>@Override
  public void onBackPressed(){
      invalidateOptionsMenu();
      if(CURRENT_FRAGMENT != FragmentMapa.FRAGMENT_NAME){//"com.ingartek.bizkaimove.ui.FragmentMapa"){
          mDrawer.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED, mDrawerRightRelativeLayout);
      }
  
      if(mDrawer.isDrawerOpen(GravityCompat.START)){
          mDrawer.closeDrawer(GravityCompat.START);
          setToolbarSubtitle(mSubtitleAux);
      }else{
          setToolbarSubtitle(getString(R.string.app_name_subtitle));
          if (getSupportFragmentManager().getBackStackEntryCount() == 1){
              //finish();
              showExitDialog();
          }else {
              super.onBackPressed();
              popFragment();
          }
      }
  
  }
  </code></pre>
  
  <p>I think I should rewrite this part:</p>
  
  <pre><code>}else {
       super.onBackPressed();
       popFragment();
  }
  </code></pre>
  
  <p><strong>Solution:</strong>
  As @Ajay Pandya suggested, I leave the onBackPressed() that way:</p>
  
  <pre><code>@Override
  public void onBackPressed(){
      invalidateOptionsMenu();
      if(CURRENT_FRAGMENT != FragmentMapa.FRAGMENT_NAME){//"com.ingartek.bizkaimove.ui.FragmentMapa"){
          mDrawer.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED, mDrawerRightRelativeLayout);
      }
  
      if(mDrawer.isDrawerOpen(GravityCompat.START)){
          mDrawer.closeDrawer(GravityCompat.START);
          setToolbarSubtitle(mSubtitleAux);
      }else{
          setToolbarSubtitle(getString(R.string.app_name_subtitle));
          if (getSupportFragmentManager().getBackStackEntryCount() &gt; 0) {
              if (getSupportFragmentManager().getBackStackEntryCount() == 1){
                  //finish();
                  showExitDialog();
              }else{
                  mFragmentManager.popBackStackImmediate();
              }
          } else {
              super.onBackPressed();
          }
      }
  
  }
  </code></pre>