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 禁止屏幕随手机旋转变化 有时候我们希望让一个程序的界面始终保持在一个方向,不随手机方向旋转而变 ...
随机推荐
- 【.Net Remoting-1】
[.NetRemoting]2015.09.16 [分布式应用程序] 应用程序分布在不同计算机上,通过网络来共同完成一项任务 C/S架构[模式] [互操作性,Interoperability]又称[互 ...
- Spark IDEA开发环境构建
本文档基于IEDA构建spark maven应用. date: 2016/8/1 author: wangxl 1.下载IDEA https://www.jetbrains.com/idea/ 2.安 ...
- Link-Cut-Tree题目泛做(为了对应自己的课件)
题目1:BZOJ 2049 洞穴勘测 #include <bits/stdc++.h> #define L(x) c[x][0] #define R(x) c[x][1] using na ...
- (原)不明白JNI指针调用顺序
很不明白JNI里面获取指针的顺序(可能这样描述不太恰当吧). 下面按照传入指针的顺序的代码一跑就崩溃.如下: JNIEXPORT jint JNICALL Java_com_example_X_XX_ ...
- shell script中的$*和$@
在shell script中,$*和$@都是获取所有的命令行参数,但是这两者在使用的过程中会有细微的差别,差别主要是在有没有使用双引号,即是直接使用$*,$@,还是使用"$*",& ...
- user密码
一.修改密码 alter user hr identified by hr; password/passw hr: SYS@test>password hr Changing password ...
- PIL参考手册
Python Imaging Library Handbook http://effbot.org/imagingbook/pil-index.htm 随机验证码的产生 import Image, I ...
- .net 拉姆达 groupby(p => p.X) order by count(c.Count())
//国家 var entityCountriesList = aliexpressEntities.SYS_CourierCode.Where(whereSelect.Compile()).Group ...
- 七、适配器(Adapter)模式--结构模式(Structural Pattern)
适配器模式:把一个类的接口变换成客户端所期待的另一种接口,从而使原本接口不匹配而无法在一起工作的两个类能够在一起工作. 类的 Adapter模式的结构: 类适配器类图: 由图中可以看出,Adaptee ...
- Yslow-23条规则编辑
1. 减少HTTP请求次数 合并图片.CSS.JS,改进首次访问用户等待时间. 2. 使用CDN 就近缓存==>智能路由==>负载均衡==>WSA全站动态加速 3. 避免空的 ...