时间:2022-06-11 10:09:45 | 栏目:Android代码 | 点击:次
第一种(Handler+标志位)
第二种(记录点击的时间)
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if(keyCode==KeyEvent.KEYCODE_BACK){
long currentTime = System.currentTimeMillis();
if(currentTime-exitTimeMillis==0||currentTime-exitTimeMillis>1500){
exitTimeMillis = System.currentTimeMillis();
Toast.makeText(this, "再按一次推出程序", 1000).show();
return false;
}else{
finish();
}
}
return super.onKeyDown(keyCode, event);
}