title: Alert dialog required two times back to finish activity
body: <p>In my activity I am showing spinner when user press POWER button spinner show successfully if user select any option is work fine but when user press back its required two times back press to show original activity what do i do? how to close and finish activity just single back press???</p>
  
  <pre><code>public class ActivityHome extends Activity  {
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      // TODO Auto-generated method stub
      super.onCreate(savedInstanceState);
           setContentView(R.layout.mainactivity);
  }
  
  @Override
  public boolean onKeyDown(int keyCode, KeyEvent event) {
     if(KeyEvent.KEYCODE_POWER == event.getKeyCode() &amp;&amp; isRooted()) {     
          startActivity(new Intent(ActivityHome.this, Spinnermenu.class));        
          return true;      
      }
      return super.onKeyDown(keyCode, event);
  }
  
  public class Spinnermenu  extends Activity {
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      // TODO Auto-generated method stub
      super.onCreate(savedInstanceState);     
      final String items[] = {"Power off","Restart"};
      AlertDialog.Builder ab=new AlertDialog.Builder(Spinnermenu.this);
      ab.setTitle("Power Options");
      ab.setItems(items, new DialogInterface.OnClickListener() {
      public void onClick(DialogInterface d, int choice) {
          if(choice == 0) {       
                      Toast.makeText(Spinnermenu.this,"PowerOff Perform",Toast.LENGTH_SHORT).show();                      
          }
          else if(choice == 1) {
  
          }
      });
      ab.show();
      public boolean onKeyDown(int keyCode, KeyEvent event) 
      {
         if(keyCode==KeyEvent.KEYCODE_BACK){
              this.finish ();
         }
         return true;
       }
  }
  </code></pre>