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();
	}

 

posted @ 2014-11-01 17:05  noodlesonce  阅读(165)  评论(0编辑  收藏  举报