码迷,mamicode.com
首页 > 移动开发 > 详细

android实现双击back键退出

时间:2014-11-01 17:38:13      阅读:167      评论:0      收藏:0      [点我收藏+]

标签:android   blog   io   ar   sp   div   on   art   log   

	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键退出

标签:android   blog   io   ar   sp   div   on   art   log   

原文地址:http://www.cnblogs.com/noodlesonce/p/4067403.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!