title: Fragment Page stack count always 0 in android
body: <p>I am trying to go back to the previous fragments when click back button. If there is no pages available in page stack it should show press back again to exit.</p>
  
  <p>I am trying like this.</p>
  
  <pre><code>@Override
      public boolean onKeyDown(int keyCode, KeyEvent event) {
          if (keyCode == KeyEvent.KEYCODE_BACK &amp;&amp; event.getRepeatCount() == 0) {
              int pageCount = getFragmentManager().getBackStackEntryCount();
              if (pageCount != 0) {
                  this.getFragmentManager().popBackStack();
                  return true;
              } 
              else
              {
                   if (doubleBackToExitPressedOnce) {
                          super.onBackPressed();
                          return true;
                      }
  
                      this.doubleBackToExitPressedOnce = true;
                      Toast.makeText(this, "Please click BACK again to exit", Toast.LENGTH_SHORT).show();
  
                      new Handler().postDelayed(new Runnable() {
  
                          @Override
                          public void run() {
                              doubleBackToExitPressedOnce=false;                       
                          }
                      }, 2000);
              }
          }
  
          return super.onKeyDown(keyCode, event);
      }
  </code></pre>
  
  <p>Here I check the page count. But it always showing 0. </p>
  
  <p>I always add this line in all <code>fragment.replace</code></p>
  
  <pre><code>FragTrans.addToBackStack(null);
  </code></pre>
  
  <p>Please help me to resolve the problem. When I click the back button It should go to the previous page. If there is no pages is available mean it should show the toast message.</p>