android学习---屏幕旋转
/**
*问题:今天学习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学习---屏幕旋转的更多相关文章
- Android 禁止屏幕旋转 & 旋转屏幕时保持Activity内容
Android 禁止屏幕旋转 & 旋转屏幕时保持Activity内容 1.在应用中固定屏幕方向. 在AndroidManifest.xml的activity中加入: ...
- Android 禁止屏幕旋转、避免转屏时重启Activity
一.禁止屏幕旋转 在AndroidManifest.xml的每一个需要禁止转向的Activity配置中加入android:screenOrientation属性: 可选项: landscape = 横 ...
- 【分享】迅为iTOP4412开发板-Android系统屏幕旋转设置
1.1概述 Android4.0,Androd4.4源代码能够编译成手机模式和平板模式,讯为iTop4412 开发平台 的Android系统默认编译为平板模式.客户须要依据自己的产品设计及应用环境,切 ...
- Android设置屏幕旋转后保存数据
1.onCreate()方法中最后判断需要保存的状态值 if(savedInstanceState != null){ mCurrentIndex = savedInstanceState.getIn ...
- 【Android】[转] Android屏幕旋转使用OrientationEventListener的监听
说明 遇到一个奇葩的问题,我在使用onConfigChanged拦截屏幕的横竖屏旋转时,发现直接进行180度的横屏/竖屏转换居然没有反应!查找原因发现仅对landscape或者portrait状态有用 ...
- Android 屏幕旋转 处理 AsyncTask 和 ProgressDialog 的最佳方案
的最佳方案 标签: Android屏幕旋转AsyncTaskProgressDialog 2014-07-19 09:25 39227人阅读 评论(46) 收藏 举报 分类: [android 进阶之 ...
- Qt for Android 程序禁止屏幕旋转
有时候我们希望让一个程序的界面始终保持在一个方向,不随手机(平板)方向旋转而变化:在AndroidManifest.xml的每一个需要禁止转向的Activity配置中加入 android:screen ...
- 设置Android默认锁定屏幕旋转
/********************************************************************************** * 设置Android默认锁定屏 ...
- 【转】如何在 Android 程序中禁止屏幕旋转和重启Activity
原文网址:http://www.cnblogs.com/bluestorm/p/3665890.html 禁止屏幕随手机旋转变化 有时候我们希望让一个程序的界面始终保持在一个方向,不随手机方向旋转而变 ...
随机推荐
- Android SDK代理服务器解决国内不能更新下载问题(转)
言:Android SDK代理服务器解决国内Android SDK不能更新下载问题,经常会遇到Fitch fail URL错误,要不就是Nothing was installed.目下Google遭受 ...
- iOS-设计模式之代理反向传值
代理设计模式就是自己的方法自己不实现,让代理对象去实现. 可以让多个类实现一组方法. 委托模式的好处在于: 1.避免子类化带来的过多的子类以及子类与父类的耦合 2.通过委托传递消息机制实现分层解耦 代 ...
- oracle 两个时间相减
oracle 两个时间相减默认的是天数 oracle 两个时间相减默认的是天数*24 为相差的小时数 oracle 两个时间相减默认的是天数*24*60 为相差的分钟数 oracle 两个时间相减默认 ...
- javaScript给元素添加多个class
<html> <head> <style type="text/css"> .div2{ font-size:16px; color:orang ...
- WordPress插件制作教程(一): 如何创建一个插件
上一篇还是按照之前的教程流程,写了一篇WordPress插件制作教程概述,从这一篇开始就为大家具体讲解WordPress插件制作的内容.这一篇主要说一下插件的创建方法. 相信大家都知道插件的安装文件在 ...
- automation studio 6.0 破解版 32位
破解软件在iso文件的patch目录下 链接:http://pan.baidu.com/s/1o8KR7rc 密码:y87g
- SQL Server索引 - 聚集索引、非聚集索引、非聚集唯一索引 <第八篇>
聚集索引.非聚集索引.非聚集唯一索引 我们都知道建立适当的索引能够提高查询速度,优化查询.先说明一下,无论是聚集索引还是非聚集索引都是B树结构. 聚集索引默认与主键相匹配,在设置主键时,SQL Ser ...
- JavaScript为unicode编码转换为中文
代码laycode - v1.1 关于这样的数据转换为中文问题,常用的以下方法. 1. eval解析或new Function("'+ str +'")() str = eval ...
- 前台利用jcrop做头像选择预览,后台通过django利用Uploadify组件上传图最终使用PIL做图像裁切
之前一直使用python的PIL自定义裁切图片,今天有需求需要做一个前端的选择预览页面,索性就把这个功能整理一下,分享给大家. 实现思路: 1.前端页面: 用户选择本地一张图片,然后通过鼠标缩放和移动 ...
- awk 处理
find . -type f | awk '{print $NF}' | grep pdf$ |grep -v preview | while read A; do ls -ltr $A| awk ' ...