title: AlertBox calls Intent without click on positive button
body: <p>Sorry to ask this question again but I tried several solutions on stackoverflow and other android groups but none of them worked for me.</p>
  
  <p>In an activity onBackpressed I want to display an alert box asking user "Exit Application?" and if user clicks on YES I want to goto launcher (home) activity of my app else stay on same page on click to NO button.
  Problem is that after displaying alert box I'm automatically redirected to launcher (home) activity automatically before I press YES button </p>
  
  <p>Plz help</p>
  
  <p>CODE:</p>
  
  <pre><code>public void onBackPressed() {
  // TODO Auto-generated method stub
  super.onBackPressed();
  Log.i(TAG, "BACK PRESSED");
  AlertDialog.Builder renameDialog = new AlertDialog.Builder(MainMenu.this);
  renameDialog.setTitle("Warning");
  renameDialog.setMessage("Do you want to logout?");
  renameDialog.setPositiveButton("OK", new DialogInterface.OnClickListener() {
  public void onClick(DialogInterface arg0, int arg1) {
  launchIntent();
  }
   });
  
  renameDialog.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
  public void onClick(DialogInterface arg0, int arg1) {
  arg0.cancel();       
  }
   });
  renameDialog.show();
  }
  
   private void launchIntent() {
  Log.i("positive button","pressed");
  Intent i=new Intent(MainMenu.this,LoginActivity.class);
  i.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
  Log.e("from main menu","calling login");
  startActivity(i); 
  }
  </code></pre>