-
-
Save nibocn/417976f1298b75ed46e4 to your computer and use it in GitHub Desktop.
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