在一些特殊的情况中,我们可能希望当一种或者多种配置改变时避免重新启动你的activity。你可以通过在manifest中设置android:configChanges属性来实现这点。
1.首先权限声明
<uses-permission Android:name="android.permission.CHANGE_CONFIGURATION"></uses-permission>
2. 声明activity要捕获的事件类型
android:configChanges="orientation|keyboard"
可选值:
- “mcc“移动国家号码,由三位数字组成,每个国家都有自己独立的MCC,可以识别手机用户所属国家。
- “mnc“移动网号,在一个国家或者地区中,用于区分手机用户的服务商。
- “locale“ 用户所在地区发生变化。
- “touchscreen“ The touchscreen has changed. (This should never normally happen.)
- “keyboard“ 键盘模式发生变化,例如:用户接入外部键盘输入。
- “keyboardHidden“ 用户打开手机硬件键盘
- “navigation“ The navigation type has changed. (This should never normally happen.)
- “orientation“ 设备旋转,横向显示和竖向显示模式切换。
- “fontScale“ 全局字体大小缩放发生改变
需要注意的地方
设置屏幕旋转不重新执行onCreate方法配置configChanges为;
android:configChanges="orientation|screenSize">
6/3/2015 6:22:10 PM