/**

*问题:今天学习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. Entity Framework中实现查询的几种方法

    在介绍几种方法前,献上一张图,希望图的作者不要追究我的盗图之过.本文的内容是我自学时的笔记,自学的内容来自网络.手打的代码,切不可直接复制过去用,会有好多错别字什么的. Entity SQL 类似于S ...

  2. Android——ExpandableListView事件拦截

    1.满足条件 如果使用ExpandableListView,需要子item响应一个事件,比如重新启动一个新的activity,需要满足下面的条件: (1).修改Adapter返回值 覆写BaseExp ...

  3. OC对象:封装、继承、多态的使用举例一

    // 该代码在网上找的视频中的例子,感觉很适合类和对象分不清楚的同学参考,仅供学习分享,谢谢 // 创建一个Pointtest类,用属性x.y表示点的坐标位置,求两点之间的距离,使用两种方法:类方法和 ...

  4. hitTest:withEvent:方法(此方法可实现点击穿透、点击下层视图功能)

    此方法可实现点击穿透.点击下层视图功能 一. hitTest:withEvent:调用过程 iOS系统检测到手指触摸(Touch)操作时会将其放入当前活动Application的事件队列,UIAppl ...

  5. SQL Server一些常见却不太记得住的命令

    一.数据库大小查询 1. exec sp_spaceused '表名'          --(SQL统计数据,大量事务操作后可能不准)2. exec sp_spaceused '表名', true  ...

  6. slf4j绑定log4j失败

    1,出现问题的配置 <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-api< ...

  7. 【转】对memcached使用的总结和使用场景

    原文连接:http://blog.csdn.net/ajun_studio/article/details/6745791# 原文作者:halfMe 转载注明以上信息! 1.memcached是什么 ...

  8. Hopscotch(POJ 3050 DFS)

    Hopscotch Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 2845   Accepted: 1995 Descrip ...

  9. mysqldump 的方式来搭建master-->slave 的复制架构

    1.master 上要满足的最小条件: 1.server_id 已经设置成了一个非0值 2.log_bin 配置好binlog 2.slave 上要满足的最小条件 1.server_id 已经设置成了 ...

  10. CSS基础-引入方法,选择器,继承

    一.CSS引入方法:行内式.嵌入式.导入式.链接式. 1.行内式. 即:在标签的style属性中设定CSS样式. 例子:<div style="行内式</div> 2.嵌入 ...