Skip to content

Instantly share code, notes, and snippets.

@nibocn
Forked from RichardNi/Android模拟双击.java
Last active August 29, 2015 14:14
Show Gist options
  • Save nibocn/417976f1298b75ed46e4 to your computer and use it in GitHub Desktop.
Save nibocn/417976f1298b75ed46e4 to your computer and use it in GitHub Desktop.
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);
  }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment