//我们需要在MainActivity中重写这个方法即可
@Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
switch (keyCode){
//点击了返回键 走这里
case KeyEvent.KEYCODE_BACK:
long secondTime=System.currentTimeMillis();
if(secondTime-firstTime>2000){
Toast.makeText(MainActivity.this,"再按一次退出程序",Toast.LENGTH_SHORT).show();
firstTime=secondTime;
return true;
}else{
System.exit(0);
}
break;
}
return super.onKeyUp(keyCode, event);
}