title: onKeyDown Method override in android
body: <p>hi all i have a problem in my application
  please see the code below for reference.
  the problem that i am facing is that when i click on Back Key Button from my Simulator i want my application to ask me that Are you sure you want to exit. and when i press Yes then it should exit otherwise it should not. 
  i have done all the things but when i click on the back key button it shows me a dialog and exits automatically. whats the reason</p>
  
  <p>code:</p>
  
  <pre><code>@Override
  public boolean onKeyDown(int keyCode, KeyEvent event)  {
      if (keyCode == KeyEvent.KEYCODE_BACK) {
  
      AlertDialog.Builder alert_wifi = new AlertDialog.Builder(this);
              alert_wifi.setMessage("This is a Wi-Fi Service. Your Device does not have an active Wi-Fi Connection. Do you Want to Activate Wi-Fi Connection")
              .setPositiveButton("Yes", new DialogInterface.OnClickListener() {
                  public void onClick(DialogInterface dialog, int id) {
                  // Action for 'Yes' Button
  
                      dialog.dismiss();
  
                   ViewCamera.isStop = true;
  
                  }
                  })
              .setNegativeButton("No", new DialogInterface.OnClickListener() {
                  public void onClick(DialogInterface dialog, int id) {
                  //  Action for 'NO' Button
                  dialog.cancel();
                  loading_act.finish();
                  }
              });
              AlertDialog alert = alert_wifi.create();
              // Title for AlertDialog
              alert.setTitle("Caution!");
              alert.setIcon(R.drawable.wifi);
              // Icon for AlertDialog
              alert.show();
  
       }
  
      return super.onKeyDown(keyCode, event);
  }
  </code></pre>
  
  <p>what could be the problem please help</p>