首页 > 代码库 > android实现双击back键退出

android实现双击back键退出

	private int mBackKeyPressedTimes = 0;	@Override	public void onBackPressed() {		if (mBackKeyPressedTimes == 0) {			Toast.makeText(this, "再次按返回键退出", Toast.LENGTH_SHORT).show();			mBackKeyPressedTimes = 1;			new Thread() {				@Override				public void run() {					try {						Thread.sleep(2000);					} catch (InterruptedException e) {						e.printStackTrace();					} finally {						mBackKeyPressedTimes = 0;					}				}			}.start();			return;		}		super.onBackPressed();	}

 

android实现双击back键退出