we can see in many applications, press two return key exit, in fact, this feature is easy to implement, the following is the implementation of the code, put it in your program you can press two times the return button to quit, this function is to avoid delays and the program quit, give your program plus this simple and practical function to put:
- Package com.xuchao.test;
- Import android.app.Activity;
- Import Android.os.Bundle;
- Import android.view.KeyEvent;
- Import Android.widget.Toast;
- public class Testactivity extends Activity {
- Private long mexittime;
- public void OnCreate (Bundle savedinstancestate) {
- Super.oncreate (savedinstancestate);
- Setcontentview (R.layout.main);
- }
- public boolean onKeyDown (int keycode, keyevent event) {
- if (keycode = = Keyevent.keycode_back) {
- if ((System.currenttimemillis ()-Mexittime) > 2000) {
- Object mhelperutils;
- Toast.maketext (This, "Press again to exit the program", Toast.length_short). Show ();
- Mexittime = System.currenttimemillis ();
- } else {
- Finish ();
- }
- return true;
- }
- Return Super.onkeydown (KeyCode, event);
- }
- }