解决华为手机隐藏虚拟按键Activity被重新创建的问题

把Activity的生命周期全部打印出来,确定隐藏或显示虚拟按键时,确实导致了Activity重建

然后在onCreate方法中

Configuration configuration = getResources().getConfiguration();
String conf = JsonUtils.toJson(configuration);
LogUtils.w(conf);把当前的config打印出来
在onConfigurationChanged方法中
public void onConfigurationChanged(Configuration newConfig) {
    super.onConfigurationChanged(newConfig);
    String conf = JsonUtils.toJson(newConfig);
    LogUtils.w(conf);
}

把改变之后的config打印出来,方便知道应该在AndroidManifest.xml中写怎么写configChanges

 

比如在onCreate方法和onConfigurationChanged方法中分别是如下数据

{"appBounds":{"bottom":1792,"left":0,"right":1080,"top":0},"assetsSeq":0,"colorMode":5,"compatScreenHeightDp":509,"compatScreenWidthDp":320,"compatSmallestScreenWidthDp":320,"densityDpi":480,"extraConfig":{"hwtheme":0,"isClearCache":0,"simpleuiMode":1,"userId":0},"fontScale":1.0,"hardKeyboardHidden":2,"keyboard":1,"keyboardHidden":1,"locale":"zh_CN_#Hans","mLocaleList":{"mList":["zh_CN_#Hans"],"mStringRepresentation":"zh-Hans-CN"},"mcc":0,"mnc":0,"navigation":1,"navigationHidden":2,"nonFullScreen":0,"orientation":1,"screenHeightDp":573,"screenLayout":268435794,"screenWidthDp":360,"seq":521,"smallestScreenWidthDp":360,"touchscreen":3,"uiMode":17,"userSetLocale":false}

 

{"appBounds":{"bottom":1920,"left":0,"right":1080,"top":0},"assetsSeq":0,"colorMode":5,"compatScreenHeightDp":547,"compatScreenWidthDp":320,"compatSmallestScreenWidthDp":320,"densityDpi":480,"extraConfig":{"hwtheme":0,"isClearCache":0,"simpleuiMode":1,"userId":0},"fontScale":1.0,"hardKeyboardHidden":2,"keyboard":1,"keyboardHidden":1,"locale":"zh_CN_#Hans","mLocaleList":{"mList":["zh_CN_#Hans"],"mStringRepresentation":"zh-Hans-CN"},"mcc":0,"mnc":0,"navigation":1,"navigationHidden":2,"nonFullScreen":0,"orientation":1,"screenHeightDp":616,"screenLayout":268435810,"screenWidthDp":360,"seq":522,"smallestScreenWidthDp":360,"touchscreen":3,"uiMode":17,"userSetLocale":false}

 

则我们再configChanges中要有screenSize,screenLayout

 

你可能感兴趣的:(android)