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

private static Boolean isQuit = false; 

成都创新互联10多年成都企业网站定制服务;为您提供网站建设,网站制作,网页设计及高端网站定制服务,成都企业网站定制及推广,对集装箱等多个领域拥有丰富的营销推广经验的网站建设公司。

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; 

}


网站名称:android连续点击两次返回退出程序
分享地址:http://scyanting.com/article/ijppjj.html