Android封装再按一次退出

private static long waitTime = 2000;    
	private static long touchTime = 0;   
	public static void onKeyDown(Activity mContext,int keyCode, KeyEvent event) {  
	    if(event.getAction() == KeyEvent.ACTION_DOWN && KeyEvent.KEYCODE_BACK == keyCode) {    
	        long currentTime = System.currentTimeMillis();    
	        if((currentTime-touchTime)>=waitTime) {    
	            //让Toast的显示时间和等待时间相同  
	            Toast.makeText(mContext, "再按一次退出", (int)waitTime).show();    
	            touchTime = currentTime;    
	        }else {    
	        	mContext.finish();    
	        }    
 	    }    
	}  
	
 	public static void onBackPressed(Activity mContext) {  
	      
	       long currentTime = System.currentTimeMillis();    
	       if((currentTime-touchTime)>=waitTime) {    
	        //让Toast的显示时间和等待时间相同  
	           Toast.makeText(mContext, "再按一次退出", (int)waitTime).show();    
	           touchTime = currentTime;    
	       }else {    
	    	   mContext.finish();   
	    	   //此处注释为测底退出
//	    	   System.exit(0);
	       }    
	       
	}  
}

你可能感兴趣的:(Android封装再按一次退出)