Private long mexittime;//defines the millisecond time to press the first exit button
public boolean onKeyDown (int keycode, keyevent event) {
if (keycode = = Keyevent.keycode_back) {
if ((System.currenttimemillis ()-Mexittime) > 2000) {
Toast.maketext (This, "Press again to exit the program", Toast.length_short). Show ();
Set the value to the current millisecond value
Mexittime = System.currenttimemillis ();
} else {
Finish (); You can exit without popping up the prompt box
Builder dig = new Alertdialog.builder (this);
Dig.settitle ("Pro, OK to exit");
Dig.setpositivebutton ("OK", new Onclicklistener ()
{
public void OnClick (dialoginterface arg0, int arg1)
{
Finish ();
}
});
Dig.setnegativebutton ("Cancel", new Onclicklistener ()
{
@Override
public void OnClick (dialoginterface arg0, int arg1)
{
}
});
Dig.show ();
}
return true;
}
Return Super.onkeydown (KeyCode, event);
}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Android Program Press two times back key to exit the message