ystem.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之前
android:configChanges="orientation|keyboardHidden"
>
4.0之后
android:configChanges="keyboardHidden|orientation|screenSize"
>
------------------------------------------------------常用设置---------------------------------------------------------
1.如果你的app指定要横屏显示的话
android:screenOrientation="portrait"
>
2.如果你的app指定要竖屏显示的话
android:screenOrientation="landscape"
>