/**

*问题:今天学习android访问Servlet,Servlet给返回一个xml格式的字符串,android得到数据后将其显示到一个TextView中,发现Activity得到数据显

*   示到TextView后,如果旋转屏幕,Activity会回到初始状态,TextView中加载的内容销毁了,这在一个发布的应用中显然是不靠谱的

*原因:网上一堆搜以后,自己也实测了下,发现原来默认情况下屏幕旋转后,会调用Activity的onDestroy和onCreate方法,这样Activity就会重新加载

*     layout布局文件,一切回到原点,TextView中自然没数据了

*解决办法:在AndroidManifest.xml中给Activity加配置属性,黄色背景字段,添加该配置后就不会再调用onDestroy和onCreate方法,而是会调用

*       onConfigurationChanged方法以新的屏幕尺寸来设置这个Activity   

<activity  android:name="com.example.androidweb.xml.XmlActivity"
     android:label="@string/xml_parse"
       android:configChanges="orientation|screenSize">
</activity>

*/

/**测试截图**********************************************************************/

/**加了配置,(图中的create调用了是第一次调用,不是横屏的时候调用的,截图时疏忽了)*/

/**没有加配置**********************************************************/

/**来段源码,英文有限,意会即可****************************************************************/

/**
* Called by the system when the device configuration changes while your
* activity is running.
* (当activity运行时,你的设备属性发生变化系统将会调用(该方法))
* Note that this will <em>only</em> be called if
* you have selected configurations you would like to handle with the
* {@link android.R.attr#configChanges} attribute in your manifest.
* 需要注意的是,当且仅当你在manifest文件(AndroidManifest.xml)中配置了android.R.attr#configChanges对
* 应的属性(onconfigChanges属性),该方法才会被调用
* If any configuration change occurs that is not selected to be reported
     * by that attribute, then instead of reporting it the system will stop
* and restart the activity (to have it launched with the new
* configuration).
* 如果没有配置该属性,那么当任何配置属性发生变化时,系统将会停止并重启该activity,而不是以新属性重新配置activity
* <p>At the time that this function has been called, your Resources
* object will have been updated to return resource values matching the
* new configuration.
*
* @param newConfig The new device configuration.
*/
public void onConfigurationChanged(Configuration newConfig) {
if (DEBUG_LIFECYCLE) Slog.v(TAG, "onConfigurationChanged " + this + ": " + newConfig);
mCalled = true; mFragments.dispatchConfigurationChanged(newConfig);//配置fragment if (mWindow != null) {
// Pass the configuration changed event to the window
mWindow.onConfigurationChanged(newConfig);//有window对象,配置window
} if (mActionBar != null) {
// Do this last; the action bar will need to access
// view changes from above.
mActionBar.onConfigurationChanged(newConfig);//有actionBar,配置actionBar
}
}

android学习---屏幕旋转的更多相关文章

  1. Android 禁止屏幕旋转 & 旋转屏幕时保持Activity内容

    Android 禁止屏幕旋转 & 旋转屏幕时保持Activity内容   1.在应用中固定屏幕方向.        在AndroidManifest.xml的activity中加入:     ...

  2. Android 禁止屏幕旋转、避免转屏时重启Activity

    一.禁止屏幕旋转 在AndroidManifest.xml的每一个需要禁止转向的Activity配置中加入android:screenOrientation属性: 可选项: landscape = 横 ...

  3. 【分享】迅为iTOP4412开发板-Android系统屏幕旋转设置

    1.1概述 Android4.0,Androd4.4源代码能够编译成手机模式和平板模式,讯为iTop4412 开发平台 的Android系统默认编译为平板模式.客户须要依据自己的产品设计及应用环境,切 ...

  4. Android设置屏幕旋转后保存数据

    1.onCreate()方法中最后判断需要保存的状态值 if(savedInstanceState != null){ mCurrentIndex = savedInstanceState.getIn ...

  5. 【Android】[转] Android屏幕旋转使用OrientationEventListener的监听

    说明 遇到一个奇葩的问题,我在使用onConfigChanged拦截屏幕的横竖屏旋转时,发现直接进行180度的横屏/竖屏转换居然没有反应!查找原因发现仅对landscape或者portrait状态有用 ...

  6. Android 屏幕旋转 处理 AsyncTask 和 ProgressDialog 的最佳方案

    的最佳方案 标签: Android屏幕旋转AsyncTaskProgressDialog 2014-07-19 09:25 39227人阅读 评论(46) 收藏 举报 分类: [android 进阶之 ...

  7. Qt for Android 程序禁止屏幕旋转

    有时候我们希望让一个程序的界面始终保持在一个方向,不随手机(平板)方向旋转而变化:在AndroidManifest.xml的每一个需要禁止转向的Activity配置中加入 android:screen ...

  8. 设置Android默认锁定屏幕旋转

    /********************************************************************************** * 设置Android默认锁定屏 ...

  9. 【转】如何在 Android 程序中禁止屏幕旋转和重启Activity

    原文网址:http://www.cnblogs.com/bluestorm/p/3665890.html 禁止屏幕随手机旋转变化 有时候我们希望让一个程序的界面始终保持在一个方向,不随手机方向旋转而变 ...

随机推荐

  1. 转帖:深入理解JavaScript系列

    感觉汤姆大叔这个系列写的很是不错,很适合有js基础但是想深入又无从下手的朋友. 深入理解JavaScript系列

  2. javaScript表单焦点自动切换

    ---恢复内容开始--- <html> <head> <script> window.onload=function(){ var form=document.ge ...

  3. OpenCV——IplImage

    IplImage结构: typedef struct _IplImage { int nSize; /* IplImage大小 */ int ID; /* 版本 (=0)*/ int nChannel ...

  4. Windows7下MySQL5.6.15免安装版的配置(来自yang362046076)

    1.下载mysql-5.5.20-win32.zip,解压到D:\dev,D盘的dev文件夹下就会出现mysql-5.5.20-win32目录,将其重命名为mysql. 2.配置MYSQL的环境变量  ...

  5. [转]fatal error: iostream.h: No such file or directory

    iostream.h是非标准头文件,iostream是标准头文件形式.iostream.h时代没有名词空间,即所有库函数包括头文件iostream.h都声明在全局域.为了体现结构层次,c++标准委员会 ...

  6. python之5关于_name_和_main_的具体含义

    关于_name_和_main_的具体含义如下: _name_:在模块中就是模块名,在类中就是类名 _main_:模块自身 "The namespace for a module is aut ...

  7. mysql sql_mode 之 NO_ENGINE_SUBSTITUTION

    知识储备: 1.mysql 有众多的存储引擎,然而只有一个默认的存储引擎,通常来说它是innodb 2.mysql 可以通过sql_mode 来控制mysql 数据库的行为,今天我们要讲的就是no_e ...

  8. VC6.0 显示代码行号和WndTab插件

    VC6.0是一款比较稳定的功能强大的IDE,目前也有很多人在使用.但美中不足的是它不能像其他IDE那样显示行号. 这里需要用到一个插件VC6LineNumberAddin,下载地址:http://fi ...

  9. android 控件的移动

    android 控件的移动 1. Java代码 imagebutton.setOnTouchListener(newOnTouchListener(){ int[]postion=newint[]{0 ...

  10. sh里没有多行注释,只能每一行加一个#号

    sh里没有多行注释,只能每一行加一个#号.只能像这样: #-------------------------------------------- # 这是一个自动打ipa的脚本,基于webfrogs ...