美文网首页
Cancelling event due to no windo

Cancelling event due to no windo

作者: Pino | 来源:发表于2019-03-04 16:27 被阅读0次

    点击返回键报错 Cancelling event due to no window focus: KeyEvent

    // 监听手机返回键
        @Override
        public boolean onKeyDown(int keyCode, KeyEvent event) {
            if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {
             
                if (addRecordList.size() != 0 || addImgList.size() != 0 || !tvAcdLogText.getText().toString().trim().isEmpty()) {
                    dialog();
                } else {
                   // 这里是核心代码,点击返回键如果不符合条件,不要马上关闭当前页面,否则就会报标题的错误,加一个延迟器即可
                    Handler mHandler= new Handler();
                    Runnable r1 = new Runnable() {
                        @Override
                        public void run() {
                            onBackPressed();
                        }};
                    mHandler.postDelayed(r1, 300);
                }
    
    
            }
            return super.onKeyDown(keyCode, event);
        }
    
    
    
    
    
    
    
    

    相关文章

      网友评论

          本文标题:Cancelling event due to no windo

          本文链接:https://www.haomeiwen.com/subject/uhmiuqtx.html