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 禁止屏幕随手机旋转变化 有时候我们希望让一个程序的界面始终保持在一个方向,不随手机方向旋转而变 ...
随机推荐
- jQuery validate 的valid()方法一直返回true
1 调用$('#myForm').valid(),一直返回ture eg:html <form id="myForm"> <input class="f ...
- (转) Data structures
Data structures A data structure is a group of data elements grouped together under one name. Thes ...
- #pragma section
看了别人使用了#pragma section来共享变量,今天试了下 如下添加代码 #define GLOBAL_SHARED __declspec(allocate(".Shared&quo ...
- js 函数声明与函数表达式
1,变量包括全局变量和局部变量,局部变量只能在函数内部访问.如果函数传参和全局变量一样的话,即使是给全局变量赋值,这里会把全局变量当成局部变量的. 如: 1: var x='x'; 2: 3: ...
- 为js数组扩展方法
(function(global,undefined){ //javascript冒泡排序,直接添加到基础类型Array的原型上 Function.prototype.method = functio ...
- web中的中文字体的英文名称
自从font-face出现以后,字体样式就不再是web开发者的难题了,但是对于移动端的中文来说,问题还是存在的,因为中文文件大小最少要3M+,即使选择性的加载某个字的字体,那也会出现不易替换的问题,所 ...
- [C++程序设计]用数组名作函数参数
1. 用数组元素作函数实参 #include <iostream> using namespace std; int max_value(int x, int max) { return ...
- python笔记之调用系统命令
python笔记之调用系统命令 目前我使用到的python中执行cmd的方式有三种 使用os.system("cmd") 该方法在调用完shell脚本后,返回一个16位的二进制数, ...
- python随机产生4个互不相等的随机数
从0-9中随机产生4个互不相等的数, 方法一: import random s=[] while(len(s)<4): x=random.randint(0,9) if x not in s: ...
- FATE(费用背包,没懂)
FATE Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submis ...