There is no better way now. You can only determine whether the user can click and quit consecutively within 2 seconds. If yes, the user will quit. If not, the user will give up listening. The Code is as follows:
Long exitTime = 0;
Public boolean onKeyDown (int keyCode, KeyEvent event ){
If (keyCode = KeyEvent. KEYCODE_BACK
& Event. getAction () = KeyEvent. ACTION_DOWN ){
If (System. currentTimeMillis ()-exitTime)> 2000 ){
Toast. makeText (getApplicationContext (), "exit the program again ",
Toast. LENGTH_SHORT). show ();
ExitTime = System. currentTimeMillis ();
} Else {
Finish ();
System. exit (0 );
}
Return true;
}
Return super. onKeyDown (keyCode, event );
}
In addition, This sentence may be added, and the menu will show the problem of clicking no pop-up window. This problem is easy to be solved!
The Code is as follows:
You must have written this method.
@ Override
Public boolean onMenuItemSelected (int featureId, MenuItem item ){
// TODO Auto-generated method stub
Return super. onMenuItemSelected (featureId, item );
}
Modify it to this way,
Public boolean onOptionsItemSelected (MenuItem item ){
Return true;
}
Add the following code to avoid errors.
Public boolean onKeyUp (int keyCode, KeyEvent event ){
If (keyCode = KeyEvent. KEYCODE_MENU ){
This. getLocalActivityManager (). getCurrentActivity ()
. OpenOptionsMenu ();
}
Return true;
}
Finished!
Author's "step-by-step column"