Android 双击返回键退出程序

阅读更多
private booleab 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;
	}

 

你可能感兴趣的:(Android 双击返回键退出程序)