Activity与configChanges

Activity生命周期重绘

当插入SIM卡时,android 系统机制会监听到网络状态改变,重而导致Activity会重绘

  • 解决办法:

    在AndroidMainfest.xml中添加onConfigChages =“mcc|mnc”

总结

android中的组件Activity在manifest.xml文件中可以指定参数android:ConfigChanges,用于捕获手机状态的改变。在Activity中添加了android:configChanges属性,在当所指定属性(Configuration Changes)发生改变时,通知程序调用onConfigurationChanged()函数。

对android:configChanges属性,一般认为有以下几点:
  1. 不设置Activity的android:configChanges时,切屏会重新调用各个生命周期,切横屏时会执行一次,切竖屏时会执行两次

  2. 设置Activity的android:configChanges="orientation"时,切屏还是会重新调用各个生命周期,切横、竖屏时只会执行一次

  3. 设置Activity的android:configChanges="orientation|ScreenSize"时,切屏不会重新调用各个生命周期,只会执行onConfigurationChanged方法,4.0以下ScreenSize 可以换成 keyboardHidden

常用参数
  • 以下状态改变都会导致Activity重绘

android:configChanges=[“mcc”, “mnc”, “locale”,“touchscreen”, “keyboard”, “keyboardHidden”,“navigation”, “screenLayout”, “fontScale”, “uiMode”,“orientation”, “screenSize”, “smallestScreenSize”]

mcc:

The IMSI mobile country code (MCC) has changed — a SIM has been detected and updated the MCC.
IMSI(国际移动用户识别码)发生改变,检测到SIM卡,或者更新MCC

mnc:

The IMSI mobile network code (MNC) has changed — a SIM has been detected and updated the MNC.
IMSI网络发生改变,检测到SIM卡,或者更新MCC其中mcc和mnc理论上不可能发生变化

locale:

The locale has changed — the user has selected a new language that text should be displayed in.
语言发生改变,用户选择了一个新的语言,文字应该重新显示

touchscreen:

The touchscreen has changed. (This should never normally happen.)
触摸屏发生改变,这通常是不应该发生的

keyboard:

The keyboard type has changed — for example, the user has plugged in an external keyboard.
键盘类型发生改变,例如,用户使用了外部键盘

keyboardHidden:

The keyboard accessibility has changed — for example, the user has revealed the hardware keyboard.
键盘发生改变,例如,用户使用了硬件键盘

navigation:

The navigation type (trackball/dpad) has changed. (This should never normally happen.)
导航发生改变,(这通常不应该发生) 举例:连接蓝牙键盘,连接后确实导致了navigation的类型发生变化。因为连接蓝牙键盘后,我可以使用方向键来navigate了

screenLayout:

The screen layout has changed — this might be caused by a different display being activated.
屏幕的布局发生改变,这可能导致激活不同的显示

fontScale:

The font scaling factor has changed — the user has selected a new global font size.
全局字体大小缩放发生改变

orientation:

The screen orientation has changed — that is, the user has rotated the device.设备旋转,横向显示和竖向显示模式切换。

screenSize:

屏幕大小改变了

smallestScreenSize:

屏幕的物理大小改变了,如:连接到一个外部的屏幕上

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

FW_G8Z

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值