android:configChanges
来源:互联网 发布:会话php 编辑:程序博客网 时间:2024/05/22 09:01
android:configChanges这个属性主要涉及横竖屏问题
在3.2之前的版本中,只要在AndroidManifest.xml文件中对activity指定android:configChanges="keyboardHidden|orientation"属性,转屏的时候就会不再重新调用OnCreate()函数,而是调用onConfigurationChanged(),但是在android3.2之后的版本中无效,转屏后仍然会调用OnCreate(),而不是onConfigurationChanged();跟踪framework层代码,就会发现问题所在,是由于google在android4.0中添加了screensize改变的通知,在转屏的时候,不仅是orientation发生了改变,screensize同样也发生了改变,而在判断是调用onConfigurationChanged还是OnCreate时,是这么处理的:
int diff = activity.mCurrentConfig.diff(config);if (diff != 0) { // If this activity doesn't handle any of the config changes then don't bother calling onConfigurationChanged as we'regoing to destroy it.//如果这个<span></span>activity 不处理任何配置(screenSize)变化,而是直接destroy,不去调用onConfigurationChanged。if ((~activity.mActivityInfo.getRealConfigChanged() & diff) == 0) {shouldChangeConfig = true;}}public int getRealConfigChanged() {return applicationInfo.targetSdkVersion < android.os.Build.VERSION_CODES.HONEYCOMB_MR2 ? (configChanges | ActivityInfo.CONFIG_SCREEN_SIZE| ActivityInfo.CONFIG_SMALLEST_SCREEN_SIZE) : configChanges;}
通过对源码的分析,可以知道有两种方法解决这个问题:(修改AndroidManifest.xml)
1.需要加一个属性值:"screenSize",指定android:configChanges="keyboardHidden|orientation|screenSize",其他的代码原来该怎么处理就怎么处理;
2.在AndroidManifest.xml中指定targetSdkVersion为3.2以前的版本(3.2的版本号为13),系统会自动加上screenSize属性值。
比如:<uses-sdk android:minSdkVersion="3" android:targetSdkVersion="12" />
Finish!
- android ConfigChanges
- android ConfigChanges
- android:configChanges
- android:configChanges
- android:configChanges
- android:configChanges
- android:configChanges
- android:configChanges
- android:configChanges
- android:configChanges
- android:configChanges
- android:configChanges
- android:configChanges
- android:configChanges
- android:configChanges
- android:configChanges
- android:configChanges
- android:configChanges
- 使用悬浮框监听内存的使用状态 -- 附源码
- ios中图片加载并显示图标
- php学习笔记(七)
- Access restriction: The type BASE64Encoder is not accessible due to restrict
- 高斯日记
- android:configChanges
- Maven 设置编译 jdk 版本 1.7
- AD属性对照表 LDAP以及简单示例
- 文件下载
- 项目总结-简单需细致的东西
- html5 可以讓使用者輸入url網址 ,去play影片
- 传统机械硬盘和固态硬盘(SSD)的区别
- Linux shell应用1-自动配置网络
- 酷炫的微信二维码