<pre name="code" class="java"> //再按一次退出程序,timeSpace = 0;
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
Log.e("keyCode", keyCode + "");
if (keyCode == KeyEvent.KEYCODE_BACK) {
if (System.currentTimeMillis() - timeSpace > 2000) {
timeSpace = System.currentTimeMillis();
Toast.makeText(MainActivity.this, "再按一次退出程序", Toast.LENGTH_SHORT).show();
}
else {
setResult(1);//resultCode 结果码
finish();
}
}
return true;
}