android横竖屏切换后不重建不销毁Activity

在AndroidManifest.xml文件的activity节点设置属性 android:configChanges="keyboardHidden|orientation"后可以使应用横竖屏切换时,不会重启对应的 Activity重新加载。可以在对应的Activity java类中重写onConfigurationChanged(Configuration newConfig)方法来处理纵横屏各自的布局,但要记得最后调用super.onConfigurationChanged(newConfig),如果不重写此方法,系统默认使用同一布局。


从3.2版本开始,横竖屏切换时屏幕分辨率可能发生改变,configChanges加入了screenSize属性,例:android:configChanges="orientation|screenSize"

如果仍希望切换后不重建Activity,设定android:targetSdkVersion小于13即可


http://developer.android.com/guide/topics/resources/runtime-changes.html

-------------------------------------------------------------------------------------------------------

Caution: Beginning with Android 3.2 (API level 13), the"screen size" also changes when the device switches between portrait and landscapeorientation. Thus, if you want to prevent runtime restarts due to orientation change when developingfor API level 13 or higher (as declared by theminSdkVersion and targetSdkVersionattributes), you must include the "screenSize" value in addition to the "orientation" value. That is, you must decalareandroid:configChanges="orientation|screenSize". However, if your application targets API level12 or lower, then your activity always handles this configuration change itself (this configurationchange does not restart your activity, even when running on an Android 3.2 or higher device).

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值