Android tips click two exit activities

In general, a combo exit program can be set up in the main activity.

@Override
//Press the two back key to exit.
public boolean onKeyDown(int keyCode, KeyEvent event) {
//Get the key and compare two times back time is greater than 2S do not quit, otherwise quit
if (keyCode == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_DOWN) {
if (System.currentTimeMillis() - exit_time > 2000) {
Toast.makeText(MainActivity.this, "Then press Toast.LENGTH_SHORT.Show () again.
exit_time = System.currentTimeMillis();
} else {
finish();
System.exit(0);
}

return true;
}
return super.onKeyDown(keyCode, event);
}

Leave a Reply

Your email address will not be published. Required fields are marked *