private static Boolean isExit = false;private static Boolean hasTask = false;Timer tExit = new Timer();TimerTask task = new TimerTask() {@Overridepublic void run() {isExit = false;hasTask = true;}};@Overridepublic boolean onKeyDown(int keyCode, KeyEvent event) {System.out.println("TabHost_Index.java onKeyDown");if (keyCode == KeyEvent.KEYCODE_BACK) {if(isExit == false ) {isExit = true;Toast.makeText(this, "再按一次後退鍵退出應用程式", Toast.LENGTH_SHORT).show();if(!hasTask) {tExit.schedule(task, 2000);}} else {finish();System.exit(0);}}return false;}
public boolean onKeyDown(int keyCode, KeyEvent event) {if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {if ((System.currentTimeMillis() - exitTime) > 2000) {Toast.makeText(this, "再按一次退出程式", Toast.LENGTH_SHORT).show();exitTime = System.currentTimeMillis();} else {finish();}}return false;}