title: Android: Proper Way to use onBackPressed() with Toast
body: <p>I wrote a piece of code that will give the user a prompt asking them to press back again if they would like to exit. I currently have my code working to an extent but I know it is written poorly and I assume there is a better way to do it. Any suggestions would be helpful!</p>
  
  <p>Code:</p>
  
  <pre><code>public void onBackPressed(){
      backpress = (backpress + 1);
      Toast.makeText(getApplicationContext(), " Press Back again to Exit ", Toast.LENGTH_SHORT).show();
  
      if (backpress&gt;1) {
          this.finish();
      }
  }
  </code></pre>