Android 横竖屏和布局问题(2)

07-24 08:51:42.669: I/System.out(18936): ------ TestActivity onPause------
07-24 08:51:42.689: I/System.out(18936): ------ TestActivity onSaveInstanceState------
07-24 08:51:42.699: I/System.out(18936): ------ TestActivity onStop------
07-24 08:51:42.729: I/System.out(18936): ------ TestActivity onDestroy------
07-24 08:51:42.759: D/memalloc(18936): /dev/pmem: Unmapping buffer base:0x5c8c5000 size:4608000 offset:3072000
07-24 08:51:42.759: D/memalloc(18936): /dev/pmem: Unmapping buffer base:0x5cd2a000 size:10797056 offset:9261056
07-24 08:51:42.789: I/System.out(18936): ------ TestActivity onCreate------
07-24 08:51:42.859: I/System.out(18936): ------ TestActivity onStart------
07-24 08:51:42.859: I/System.out(18936): ------ TestActivity onRestoreInstanceState------
07-24 08:51:42.879: I/System.out(18936): ------ TestActivity onResume------

2)配置android:configChanges="orientation|keyboardHidden" (4.0以前)

a.正常情况下:

07-24 08:54:05.059: I/System.out(18936): ------ TestActivity onCreate------
07-24 08:54:05.199: I/System.out(18936): ------ TestActivity onStart------
07-24 08:54:05.219: I/System.out(18936): ------ TestActivity onResume------

b.切换横屏情况下:

07-24 08:54:25.909: I/System.out(18936): ------ TestActivity onPause------
07-24 08:54:25.919: I/System.out(18936): ------ TestActivity onSaveInstanceState------
07-24 08:54:25.929: I/System.out(18936): ------ TestActivity onStop------
07-24 08:54:25.949: I/System.out(18936): ------ TestActivity onDestroy------
07-24 08:54:25.979: D/memalloc(18936): /dev/pmem: Unmapping buffer base:0x5c7c5000 size:19603456 offset:18067456
07-24 08:54:25.979: D/memalloc(18936): /dev/pmem: Unmapping buffer base:0x5da77000 size:4608000 offset:3072000
07-24 08:54:26.019: I/System.out(18936): ------ TestActivity onCreate------
07-24 08:54:26.069: I/System.out(18936): ------ TestActivity onStart------
07-24 08:54:26.079: I/System.out(18936): ------ TestActivity onRestoreInstanceState------
07-24 08:54:26.079: I/System.out(18936): ------ TestActivity onResume------

c.再切换回竖屏的情况下:

07-24 08:55:02.099: I/System.out(18936): ------ TestActivity onPause------
07-24 08:55:02.109: I/System.out(18936): ------ TestActivity onSaveInstanceState------
07-24 08:55:02.119: I/System.out(18936): ------ TestActivity onStop------
07-24 08:55:02.129: I/System.out(18936): ------ TestActivity onDestroy------
07-24 08:55:02.139: D/memalloc(18936): /dev/pmem: Unmapping buffer base:0x5c7c5000 size:4608000 offset:3072000
07-24 08:55:02.139: D/memalloc(18936): /dev/pmem: Unmapping buffer base:0x5cc30000 size:9216000 offset:7680000
07-24 08:55:02.179: I/System.out(18936): ------ TestActivity onCreate------
07-24 08:55:02.249: I/System.out(18936): ------ TestActivity onStart------
07-24 08:55:02.289: I/System.out(18936): ------ TestActivity onRestoreInstanceState------
07-24 08:55:02.309: I/System.out(18936): ------ TestActivity onResume------

发觉上面的结果是跟网上的朋友说的不是一样的,原来是有区别的。

到后来去网上搜索了一下资料发觉,到了。4.0以后。要加上这样的配置才会使Activity的生命周期不会重新被调用

3)配置android:configChanges="keyboardHidden|orientation|screenSize" (4.0以后)

a.正常情况下:

07-24 08:54:05.059: I/System.out(18936): ------ TestActivity onCreate------
07-24 08:54:05.199: I/System.out(18936): ------ TestActivity onStart------
07-24 08:54:05.219: I/System.out(18936): ------ TestActivity onResume------


b.切换横屏情况下:

07-24 09:08:21.639: I/System.out(19533): ------ TestActivity onConfigurationChanged------

c.再切换回竖屏的情况下:

07-24 09:08:21.639: I/System.out(19533): ------ TestActivity onConfigurationChanged-----

总结:要想Activity在横竖屏切换的时候不重新加载生命周期的重要方法,一定要加上配置

4.0之前

<activity .....

android:configChanges="orientation|keyboardHidden"

>

4.0之后

<activity .....

android:configChanges="keyboardHidden|orientation|screenSize"

>

------------------------------------------------------常用设置---------------------------------------------------------

1.如果你的app指定要横屏显示的话

<activity .....

android:screenOrientation="portrait"

>

2.如果你的app指定要竖屏显示的话

<activity .....

android:screenOrientation="landscape"

>

Ubuntu 14.04 x64配置Android 4.4 kitkat编译环境的方法

Ubuntu 12.04搭建Android开发环境

Ubuntu 14.04 配置 Android SDK 开发环境

64位Ubuntu 11.10下Android开发环境的搭建(JDK+Eclipse+ADT+Android SDK详细)

Ubuntu 12.10 x64 安装 Android SDK

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:http://www.heiqu.com/8b58ce77014cb1b899b61ac6a2a997c1.html