title: How to avoid closing Activity when going to previous fragment
body: <p>I have an activity which consists of 2 fragments, what I have put down in my activity backpressed is something like this..    </p>
  
  <pre><code>private Boolean exit = false;
  
  @Override
  public void onBackPressed() {
      if (exit) {
          moveTaskToBack(true);    
          finish(); // finish activity
      } else {
          Toast.makeText(this, "Press Back again to Exit.",
          Toast.LENGTH_SHORT).show();
          exit = true;
          new Handler().postDelayed(new Runnable() {
              @Override
              public void run() {
                  exit = false;
              }
          }, 3 * 1000);
      }
  }
  </code></pre>
  
  <p>this  leads directly to close the app even if i am at fragment 2, actually what should happen is it should go back to fragment 1 not closed any help...</p>