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://hbruida.cn/article/ijppjj.html