title: Disable back button for previous activities, but exit with double pressed
body: <p></p>
  Is there any way to disable in an activity the back button (to prevent show the previous activities), but also when you double press it, use it for exit??
  I use this code that I found, but it only makes the second part. Close the app with double press..</p>
  What I try to do, is also prevent to go back and show the last visited activities. Thank you.</p>
  
  <pre><code>boolean doubleBackToExitPressedOnce = false;
  
  @Override
  public void onBackPressed() {
  
      if (doubleBackToExitPressedOnce) {
          super.onBackPressed();
          return;
      }
  
      this.doubleBackToExitPressedOnce = true;
      Toast.makeText(this, "Press again back for exit", Toast.LENGTH_SHORT).show();
  
      new Handler().postDelayed(new Runnable() {
  
          @Override
          public void run() {
              doubleBackToExitPressedOnce=false;
          }
      }, 2000);
  
  }
  </code></pre>
  
  <p>UPDATE</p>
  
  <p>I make the changes that you suggest, but now, it shows with the double back all the previous visited activities.</p>
  
  <pre><code>static final long THRESHOLD = 2000;
  long backLastPressed;
  
  boolean doubleBackToExitPressedOnce = false;
  
  @Override
  public void onBackPressed() {
      if (System.currentTimeMillis() - backLastPressed &lt; THRESHOLD) {
          if (doubleBackToExitPressedOnce) {
              super.onBackPressed();
              return;
          }
  
          this.doubleBackToExitPressedOnce = true;
          Toast.makeText(this, "Press again back for exit", Toast.LENGTH_SHORT).show();
  
          new Handler().postDelayed(new Runnable() {
  
              @Override
              public void run() {
                  doubleBackToExitPressedOnce=false;
              }
          }, 2000);
          backLastPressed = 0;
          return;
      }
      backLastPressed = System.currentTimeMillis();
      // Otherwise, ignore this BACK press
  }
  </code></pre>