android连续点击两次返回 退出程序

private static Boolean isQuit = false; 

Timer timer = new Timer(); 

@Override

public boolean onKeyDown(int keyCode, KeyEvent event) { 

        if (keyCode == KeyEvent.KEYCODE_BACK) { 

            if (isQuit == false) { 

                isQuit = true; 

                Toast.makeText(getBaseContext(), "再按一次返回键退出程序", Toast.LENGTH_SHORT).show(); 

                TimerTask task = null; 

                task = new TimerTask() { 

                    @Override

                    public void run() { 

                        isQuit = false; 

                    

                }; 

                timer.schedule(task, 2000); 

            } else { 

                finish(); 

                System.exit(0); 

            

        

        return false; 

}


你可能感兴趣的:(退出程序,双击)