Android 再按一次返回键退出 代码


代码是网上找的,很有用

   private boolean isfinished = false;
    @Override
    public void onBackPressed() {
        //super.onBackPressed();
        if (isfinished)
        {
            ActivityCollector.finishAll();
        } else
        {
            Toast.makeText(this, "再按一次返回键退出", Toast.LENGTH_SHORT).show();
            new Thread()
            {
                public void run()
                {
                    isfinished = true;
                    try
                    {
                        Thread.sleep(2000);
                        isfinished = false;
                    } catch (InterruptedException e)
                    {
                        e.printStackTrace();
                    }
                };
            }.start();
        }
    }


你可能感兴趣的:(android)