Last active
August 29, 2015 14:14
-
-
Save RichardNi/65e79acd326db1afc984 to your computer and use it in GitHub Desktop.
Android模拟双击按钮退出应用,转自:http://www.cnblogs.com/net168/p/4234869.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private long mPressedTime = 0; | |
@Override | |
public void onBackPressed() { | |
//获取第一次按键时间 | |
long mNowTime = System.currentTimeMillis(); | |
//比较两次按键时间差 | |
if((mNowTime - mPressedTime) > 2000){ | |
Toast.makeText(this, "再按一次退出程序", Toast.LENGTH_SHORT).show(); | |
mPressedTime = mNowTime; | |
} else {//退出程序 | |
this.finish(); | |
System.exit(0); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment