美文网首页
一个Activity不断的获取焦点和失去焦点的问题

一个Activity不断的获取焦点和失去焦点的问题

作者: 仕明同学 | 来源:发表于2018-12-20 14:13 被阅读0次
    • 手机信息
    image.png
    12-19 17:00:18.720 1564-1599/? V/WindowManager: Changing focus from null to Window{19169e4 u0 com.xfxb.shoptools.debug/com.xfxb.shoptools.ui.activity.LoginActivity}
    12-19 17:00:18.742 18243-18243/? D/CrashReport: >>> com.xfxb.shoptools.ui.activity.LoginActivity onResumed <<<
    12-19 17:00:18.758 1564-2274/? V/WindowManager: Changing focus from Window{19169e4 u0 com.xfxb.shoptools.debug/com.xfxb.shoptools.ui.activity.LoginActivity} to null
    12-19 17:00:18.775 18243-18243/? D/CrashReport: >>> com.xfxb.shoptools.ui.activity.LoginActivity onPaused <<<
    12-19 17:00:18.840 1564-1599/? V/WindowManager: Changing focus from null to Window{19169e4 u0 com.xfxb.shoptools.debug/com.xfxb.shoptools.ui.activity.LoginActivity}
                                                    
                                                    [ 12-19 17:00:18.840  1564: 1578 D/         ]
                                                    jni writeStringContentData: dataContent size:48, contentSize:48, str:com.android.packageinstaller|2018-12-19 17:00:18, dataType:9
    12-19 17:00:18.863 18243-18243/? D/CrashReport: >>> com.xfxb.shoptools.ui.activity.LoginActivity onResumed <<<
    12-19 17:00:18.882 1564-27062/? V/WindowManager: Changing focus from Window{19169e4 u0 com.xfxb.shoptools.debug/com.xfxb.shoptools.ui.activity.LoginActivity} to null
    12-19 17:00:18.901 18243-18243/? D/CrashReport: >>> com.xfxb.shoptools.ui.activity.LoginActivity onPaused <<<
                                                    
                                                    [ 12-19 17:00:18.902  1564: 1578 D/         ]
                                                    jni writeStringContentData: dataContent size:44, contentSize:44, str:com.xfxb.shoptools.debug|2018-12-19 17:00:18, dataType:9
    12-19 17:00:18.962 1564-27059/? V/WindowManager: Changing focus from null to Window{19169e4 u0 com.xfxb.shoptools.debug/com.xfxb.shoptools.ui.activity.LoginActivity}
    12-19 17:00:18.985 18243-18243/? D/CrashReport: >>> com.xfxb.shoptools.ui.activity.LoginActivity onResumed <<<
    12-19 17:00:19.007 1564-1599/? V/WindowManager: Changing focus from Window{19169e4 u0 com.xfxb.shoptools.debug/com.xfxb.shoptools.ui.activity.LoginActivity} to null
    12-19 17:00:19.029 18243-18243/? D/CrashReport: >>> com.xfxb.shoptools.ui.activity.LoginActivity onPaused <<<
    12-19 17:00:19.101 1564-2763/? V/WindowManager: Changing focus from null to Window{19169e4 u0 com.xfxb.shoptools.debug/com.xfxb.shoptools.ui.activity.LoginActivity}
    12-19 17:00:19.122 18243-18243/? D/CrashReport: >>> com.xfxb.shoptools.ui.activity.LoginActivity onResumed <<<
                                                    
                                                    [ 12-19 17:00:19.129  1564: 1578 D/         ]
                                                    jni writeStringContentData: dataContent size:44, contentSize:44, str:com.xfxb.shoptools.debug|2018-12-19 17:00:18, dataType:9
    12-19 17:00:19.139 1564-2274/? V/WindowManager: Changing focus from Window{19169e4 u0 com.xfxb.shoptools.debug/com.xfxb.shoptools.ui.activity.LoginActivity} to null
    12-19 17:00:19.158 18243-18243/? D/CrashReport: >>> com.xfxb.shoptools.ui.activity.LoginActivity onPaused <<<
    12-19 17:00:19.217 1564-2576/? V/WindowManager: Changing focus from null to Window{19169e4 u0 com.xfxb.shoptools.debug/com.xfxb.shoptools.ui.activity.LoginActivity}
    12-19 17:00:19.239 18243-18243/? D/CrashReport: >>> com.xfxb.shoptools.ui.activity.LoginActivity onResumed <<<
                                                    
                                                    [ 12-19 17:00:19.248  1564: 1578 D/         ]
                                                    jni writeStringContentData: dataContent size:44, contentSize:44, str:com.xfxb.shoptools.debug|2018-12-19 17:00:18, dataType:9
    12-19 17:00:19.258 1564-1608/? V/WindowManager: Changing focus from Window{19169e4 u0 com.xfxb.shoptools.debug/com.xfxb.shoptools.ui.activity.LoginActivity} to null
    12-19 17:00:19.279 18243-18243/? D/CrashReport: >>> com.xfxb.shoptools.ui.activity.LoginActivity onPaused <<<
    12-19 17:00:19.335 1564-27060/? V/WindowManager: Changing focus from null to Window{19169e4 u0 com.xfxb.shoptools.debug/com.xfxb.shoptools.ui.activity.LoginActivity}
    12-19 17:00:19.358 18243-18243/? D/CrashReport: >>> com.xfxb.shoptools.ui.activity.LoginActivity onResumed <<<
    12-19 17:00:19.382 1564-1608/? V/WindowManager: Changing focus from Window{19169e4 u0 com.xfxb.shoptools.debug/com.xfxb.shoptools.ui.activity.LoginActivity} to null
    12-19 17:00:19.401 18243-18243/? D/CrashReport: >>> com.xfxb.shoptools.ui.activity.LoginActivity onPaused <<<
    12-19 17:00:19.458 1564-1575/? V/WindowManager: Changing focus from null to Window{19169e4 u0 com.xfxb.shoptools.debug/com.xfxb.shoptools.ui.activity.LoginActivity}
    12-19 17:00:19.480 18243-18243/? D/CrashReport: >>> com.xfxb.shoptools.ui.activity.LoginActivity onResumed <<<
    12-19 17:00:19.499 1564-2540/? V/WindowManager: Changing focus from Window{19169e4 u0 com.xfxb.shoptools.debug/com.xfxb.shoptools.ui.activity.LoginActivity} to null
    12-19 17:00:19.516 18243-18243/? D/CrashReport: >>> com.xfxb.shoptools.ui.activity.LoginActivity onPaused <<<
    12-19 17:00:19.573 1564-27061/? V/WindowManager: Changing focus from null to Window{19169e4 u0 com.xfxb.shoptools.debug/com.xfxb.shoptools.ui.activity.LoginActivity}
    12-19 17:00:19.598 18243-18243/? D/CrashReport: >>> com.xfxb.shoptools.ui.activity.LoginActivity onResumed <<<
    12-19 17:00:19.613 1564-2274/? V/WindowManager: Changing focus from Window{19169e4 u0 com.xfxb.shoptools.debug/com.xfxb.shoptools.ui.activity.LoginActivity} to null
    12-19 17:00:19.634 18243-18243/? D/CrashReport: >>> com.xfxb.shoptools.ui.activity.LoginActivity onPaused <<<
    12-19 17:00:19.694 1564-27061/? V/WindowManager: Changing focus from null to Window{19169e4 u0 com.xfxb.shoptools.debug/com.xfxb.shoptools.ui.activity.LoginActivity}
    12-19 17:00:19.718 18243-18243/? D/CrashReport: >>> com.xfxb.shoptools.ui.activity.LoginActivity onResumed <<<
    12-19 17:00:19.734 1564-27061/? V/WindowManager: Changing focus from Window{19169e4 u0 com.xfxb.shoptools.debug/com.xfxb.shoptools.ui.activity.LoginActivity} to null
    12-19 17:00:19.755 18243-18243/? D/CrashReport: >>> com.xfxb.shoptools.ui.activity.LoginActivity onPaused <<<
    12-19 17:00:19.813 1564-2762/? V/WindowManager: Changing focus from null to Window{19169e4 u0 com.xfxb.shoptools.debug/com.xfxb.shoptools.ui.activity.LoginActivity}
    12-19 17:00:19.833 18243-18243/? D/CrashReport: >>> com.xfxb.shoptools.ui.activity.LoginActivity onResumed <<<
    12-19 17:00:19.850 1564-27063/? V/WindowManager: Changing focus from Window{19169e4 u0 com.xfxb.shoptools.debug/com.xfxb.shoptools.ui.activity.LoginActivity} to null
    12-19 17:00:19.871 18243-18243/? D/CrashReport: >>> com.xfxb.shoptools.ui.activity.LoginActivity onPaused <<<
    12-19 17:00:19.929 1564-1574/? V/WindowManager: Changing focus from null to Window{19169e4 u0 com.xfxb.shoptools.debug/com.xfxb.shoptools.ui.activity.LoginActivity}
    12-19 17:00:19.949 18243-18243/? D/CrashReport: >>> com.xfxb.shoptools.ui.activity.LoginActivity onResumed <<<
    12-19 17:00:19.968 1564-26030/? V/WindowManager: Changing focus from Window{19169e4 u0 com.xfxb.shoptools.debug/com.xfxb.shoptools.ui.activity.LoginActivity} to null
    12-19 17:00:19.988 18243-18243/? D/CrashReport: >>> com.xfxb.shoptools.ui.activity.LoginActivity onPaused <<<
    12-19 17:00:20.052 1564-27059/? V/WindowManager: Changing focus from null to Window{19169e4 u0 com.xfxb.shoptools.debug/com.xfxb.shoptools.ui.activity.LoginActivity}
    12-19 17:00:20.076 18243-18243/? D/CrashReport: >>> com.xfxb.shoptools.ui.activity.LoginActivity onResumed <<<
    12-19 17:00:20.094 1564-2541/? V/WindowManager: Changing focus from Window{19169e4 u0 com.xfxb.shoptools.debug/com.xfxb.shoptools.ui.activity.LoginActivity} to null
    12-19 17:00:20.117 18243-18243/? D/CrashReport: >>> com.xfxb.shoptools.ui.activity.LoginActivity onPaused <<<
    12-19 17:00:20.173 1564-2790/? V/WindowManager: Changing focus from null to Window{19169e4 u0 com.xfxb.shoptools.debug/com.xfxb.shoptools.ui.activity.LoginActivity}
    12-19 17:00:20.197 18243-18243/? D/CrashReport: >>> com.xfxb.shoptools.ui.activity.LoginActivity onResumed <<<
    
    • 故障截图,Activity 在不断的获取焦点和失去焦点


      image.png
    • 导致的原因
    • 在登录的Activity中的生命周期onResume中使用RxPermissions获取相机的权限,点击不让通知,拒绝权限了,这个Activity就会不断的onResumed onPaused 生命周期轮训,其他手机上没有这种问题!只在oppoR 9上有这种的问题,
    • 解决的办法
    • 把权限的检查放到onCreate的方法中,就可以解决!
       if (!aBoolean){
                        final RxPermissions rxPermissions = new RxPermissions(this);
                        rxPermissions.request(Manifest.permission.CAMERA).subscribe(new Action1<Boolean>() {
                            @Override
                            public void call(Boolean aBoolean) {
                                if (aBoolean) {
                                    boolean granted = rxPermissions.isGranted(Manifest.permission.CAMERA);
                                    if (!granted){
                                        ToastUtils.toast(LoginActivity.this,"相机权限授权成功!");
                                    }
                                    PreferenceUtil.saveValue(PreferenceFileNames.USER_CONFIG, PreferenceKeys.HAS_CAMER_PERMISSION,true);
                                } else {
                                    ToastUtils.toast(LoginActivity.this,"相机权限授权失败!");
                                }
                            }
                        });
                    }
    

    RxPermissions 还可能导致整个View的生命周期紊乱的发生

    相关文章

      网友评论

          本文标题:一个Activity不断的获取焦点和失去焦点的问题

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