android再次点击实现退出

private long lastClickBackBtnTime;
    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        super.onKeyDown(keyCode, event);
        if (keyCode == KeyEvent.KEYCODE_BACK && wv.canGoBack()) {
            wv.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);
            wv.goBack();
            return true;
        }else if(!wv.canGoBack()){
            long now=System.currentTimeMillis();
            long time=System.currentTimeMillis()-lastClickBackBtnTime;
            if(time<1000){
                return true;
            }else{
                lastClickBackBtnTime=System.currentTimeMillis();
                Toast.makeText(ctx,"再次点击退出",Toast.LENGTH_SHORT).show();
                return false;
            }
        }
        return false;
    }


你可能感兴趣的:(android再次点击实现退出)