解决华为手机隐藏虚拟按键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

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值