转: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 ...
随机推荐
- config -导航
在config进行中配置 1在config中添加SITmap <siteMap enabled="true" defaultProvider="UserSiteM ...
- MemberShip使用大全
比较全面的membership 使用过程 http://www.cnblogs.com/xlb2000/archive/2010/07/31/1788120.html Membership中创建的数据 ...
- Python之路Day17
算法:冒泡排序.插入排序.快速排序.堆排序 冒泡排序 #! /usr/bin/env python # -*- coding: utf-8 -*- # __author__ = "Q1mi& ...
- [LeetCode]题解(python):058-Length of Last Word
题目来源: https://leetcode.com/problems/length-of-last-word/ 题意分析: 给出只包括大小写和空格的字符,输出最后一个单词的长度. 题目思路: 从最后 ...
- fork 函数的一点学习
昨天某位少年问了我一个问题,#include<stdio.h> int main() { fork(); fork(); fork(); printf("hello " ...
- 深入浅出—JAVA(6)
6.认识JAVA的API Arraylist的操作
- UNIX网络编程5 POSIX 消息队列
<mqueue.h> mq_open mq_close mq_unlink mq_getattr/mq_setattr mq_send/mq_receive mq_notify sigwa ...
- Zookper
http://blog.csdn.net/yangbutao/article/details/11669609 http://www.oschina.net/code/snippet_255033_2 ...
- 一个i++和++i导致的严重的错误
当我曾经在写一个strlen的实现时,用递归写出了如下的代码: int strlen(const char *s) { if(*s=='\0') ; else ; } 程序一运行就崩溃了,why!都是 ...
- POJ-1003&1004
这两题比较简单,就不做分析了,描述下题目,就上代码吧. [题目描述] 1003,其实就是求这个方程的最小n:1/2 + 1/3 + 1/4 + ... + 1/(n + 1) >= c: 100 ...