Tuesday, January 28, 2014

Press the Return key to end the whole process twice


            
Users are given a prompt before exiting the application is necessary, because the user may not really want to quit, but only accidentally pressed the return key, the practice of the majority of applications are given before an application make way Dialog, I think this is not very friendly, user have to move your finger to press the button in the dialog. Personally feel that "press the return key to exit the program" is a best practice, implementation is very simple, direct the code:

private long exitTime = 0;

@ Override
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 (), "press again to exit the program", Toast.LENGTH_SHORT) show ();.
exitTime = System.currentTimeMillis ();
} Else {
finish ();
System.exit (0);
}
return true;
}
return super.onKeyDown (keyCode, event);
}





Found finish ();
System.exit (0);
Did not able to end the entire program, but off the current page, not jump off the splash screen page, ask how the end of the whole process.
Reply:
Ah, this program is not wrong. .
Reply:
You jump to the page when the page did not finish out of it before?
Every time I finish what jumps.
Reply:
System.exit (0); and finish (); effect, are to close the current Activity
Reply:
Yes, ah, jump to the page when the page did not finish off before.

No comments:

Post a Comment