转:onConfigurationChanged的作用
API原文说明:
android:configChanges
Lists configuration changes that the activity will handle itself. When a configuration change occurs at runtime, the activity is shut down and restarted by default, but declaring a configuration with this attribute will prevent the activity from being restarted. Instead, the activity remains running and its onConfigurationChanged() method is called.
Any or all of the following strings are valid values for this attribute. Multiple values are separated by '|' — for example, "locale|navigation|orientation".

All of these configuration changes can impact the resource values seen by the application. Therefore, when onConfigurationChanged() is called, it will generally be necessary to again retrieve all resources (including view layouts, drawables, and so on) to correctly handle the change.
在一些特殊的情况中,你可能希望当一种或者多种配置改变时避免重新启动你的activity。你可以通过在manifest中设置android:configChanges属性来实现这点。
你可以在这里声明activity可以处理的任何配置改变,当这些配置改变时不会重新启动activity,而会调用activity的
onConfigurationChanged(Resources.Configuration)方法。如果改变的配置中包含了你所无法处理的配置(在android:configChanges并未声明),
你的activity仍然要被重新启动,而onConfigurationChanged(Resources.Configuration)将不会被调用。
其次:android:configChanges=""中可以用的值:keyboard|mcc|mnc|locale|touchscreen|keyboardHidden|navigation|orientation……
Configuration 类中包含了很多种信息,例如系统字体大小,orientation,输入设备类型等等.(如上图)
比如:android:configChanges="orientation|keyboard|keyboardHidden"
当Configuration改变后,ActivityManagerService将会发送"配置改变"的广播,会要求ActivityThread 重新启动当前focus的Activity.
这是默认情况,我们不做任何处理,如果我们android:configChanges来配置Activity信息,那么就可以避免对Activity销毁再重新创建,而是调用
onConfigurationChanged方法。
通过查阅Android API可以得知android:onConfigurationChanged实际对应的是Activity里的onConfigurationChanged()方法。
在AndroidManifest.xml中添加上诉代码的含义是表示在改变屏幕方向、弹出软件盘和隐藏软键盘时,不再去执行onCreate()方法,
而是直接执行onConfigurationChanged()。如果不申明此段代码,按照Activity的生命周期,都会去执行一次onCreate()方法,而onCreate()方法通常会在显示之前做一些初始化工作。所以如果改变屏幕方向这样的操作都去执行onCreate()方法,就有可能造成重复的初始化,降低程序效率是必然的了,而且更有可能因为重复的初始化而导致数据的丢失。这是需要千万避免的。
参考:
Android学习笔记——关于onConfigurationChanged
http://www.cnblogs.com/wisekingokok/archive/2011/10/06/2199948.html
http://www.cnblogs.com/bluestorm/p/3622444.html
onConfigurationChanged信息处理 监听屏幕旋转 语言变换 键盘滑动
http://fghzhaopai.blog.163.com/blog/static/4780555620116882211560/
转:onConfigurationChanged的作用的更多相关文章
- Android onConfigurationChanged的作用
API原文说明: android:configChangesLists configuration changes that the activity will handle itself. When ...
- [Android Pro] AsyncTaskLoader vs AsyncTask
reference to : http://blog.csdn.net/a910626/article/details/45599133 我看了一下asyncTask是从LV3开始,AsyncTask ...
- onWindowFocusChanged重要作用 and Activity生命周期
onWindowFocusChanged重要作用 Activity生命周期中,onStart, onResume, onCreate都不是真正visible的时间点,真正的visible时间点是onW ...
- if __name__== "__main__" 的意思(作用)python代码复用
if __name__== "__main__" 的意思(作用)python代码复用 转自:大步's Blog http://www.dabu.info/if-__-name__ ...
- (转载)linux下各个文件夹的作用
linux下的文件结构,看看每个文件夹都是干吗用的/bin 二进制可执行命令 /dev 设备特殊文件 /etc 系统管理和配置文件 /etc/rc.d 启动的配置文件和脚本 /home 用户主目录的基 ...
- github中的watch、star、fork的作用
[转自:http://www.jianshu.com/p/6c366b53ea41] 在每个 github 项目的右上角,都有三个按钮,分别是 watch.star.fork,但是有些刚开始使用 gi ...
- web.xml中welcome-file-list的作用
今天尝试使用struts2+ urlrewrite+sitemesh部署项目,结果发现welcome-file-list中定义的欢迎页不起作用: <welcome-file-list> & ...
- web.xml中load-on-startup的作用
如下一段配置,熟悉DWR的再熟悉不过了:<servlet> <servlet-name>dwr-invoker</servlet-name> <ser ...
- SQLSERVER中NULL位图的作用
SQLSERVER中NULL位图的作用 首先感谢宋沄剑提供的文章和sqlskill网站:www.sqlskills.com,看下面文章之前请先看一下下面两篇文章 SQL Server误区30日谈-Da ...
随机推荐
- js设置奇偶行数样式
$(document).ready(function () { odd = { "background": "none" }; //奇数样式 even = { ...
- Ext JS学习第十四天 Ext基础之 Ext.DomHelper
此文用来记录学习笔记 •我们已经学过了Element这个类,无疑是非常强大的,里面提供了丰富的方法供我们使用,但是Ext为了更加的方便我们去操作DOM元素,特提供了DomHelper这个辅助的工具 ...
- 用nodejs安装hexo,将hexo部署到github
跌跌撞撞写这篇博文,希望下一篇可以好点 运行环境:最新版本的nodejs + git 安装好nodejs 和 git ,注册好github账号,新建仓库****.github.io(****为gith ...
- JavaSE学习总结第17天_集合框架3
17.01 ArrayList集合的toString()方法源码解析 代码: Collection c = new ArrayList(); c.add("hello"); c ...
- foreach遍历对象的属性
<?php class MyClass { public $var1 = 'value 1' ; public $var2 = 'value 2' ; public $var3 = 'value ...
- commons-logging \ log4j \ slf4j 之间的关系
最近的一个web项目中要使用到日志,但是对常用的日志记录工具(框架)着实不是很理解,在此mark一下. 1.commons-logging.jar common-logging是apache提供的一个 ...
- An update on OS X Code Signing(OS X代码签名)
There has recently been updates to the OS X code signing process. These updates also affect Qt appli ...
- 我在北京找工作(二):java实现算法<1> 冒泡排序+直接选择排序
工作.工作.找工作.经过1个多星期的思想斗争还是决定了找JAVA方面的工作,因为好像能比PHP的工资高点.呵呵 :-) (其实我这是笑脸,什么QQ输入法,模拟表情都没有,忒不人性化了.) 言归正传, ...
- [每日一题] 11gOCP 1z0-052 :2013-09-14 repeated parsing activity.................................A70
转载请注明出处:http://blog.csdn.net/guoyjoe/article/details/11699299 正确答案:D SQL语句的执行过程: 1.客户端输入sql语句update ...
- uva - The Lottery(容斥,好题)
10325 - The Lottery The Sports Association of Bangladesh is in great problem with their latest lotte ...