android:configChanges不被調用的問題,
同樣是由於SDK版本引發的問題。版本高的更加嚴謹,限制更多。
"orientation" |
The screen orientation has changed — the user has rotated the device. Note: If your application targets API level 13 or higher (as declared by the minSdkVersion and targetSdkVersion attributes), then you should also declare the "screenSize" configuration, because it also changes when a device switches between portrait and landscape orientations. |
"screenSize" |
The current available screen size has changed. This represents a change in the currently available size, relative to the current aspect ratio, so will change when the user switches between landscape and portrait. However, if your application targets API level 12 or lower, then your activity always handles this configuration change itself (this configuration change does not restart your activity, even when running on an Android 3.2 or higher device). Added in API level 13. |
So,大意就是SDK版本13或以上的,需要同時用orientation與screenSize。因為當裝置橫豎屏切換時,相應的螢幕大小也改變了。所以在Activity配置中正確寫法為
android:configChanges="orientation|screenSize"
同時,我們可以知道screenSize這個配置改變並不會導致Activity的reStart。