android开发按两次返回键退出整个程序

代码:

 private boolean is2CallBack = false;   
    
    @Override  
      public boolean onKeyDown(int keyCode, KeyEvent event) {   
           // TODO Auto-generated method stub   
              
           if( keyCode == KeyEvent.KEYCODE_BACK){   
               if(!is2CallBack){   
                        is2CallBack = true;   
                        Toast.makeText(this, "再按一次退出程序", Toast.LENGTH_SHORT).show();    
                        new Handler().postDelayed(new Runnable() {   
                               @Override  
                              public void run() {   
                                   is2CallBack = false;   
                            }   
                          }, 2500);   
                          
                   }else {   
                       android.os.Process.killProcess(android.os.Process.myPid());   
                     }   
           }   
          return true;   
       }  


 

你可能感兴趣的:(callback,返回键退出程序)