分享

Android4.0转屏禁止重新onCreate()

 勤奋不止 2013-05-15
solution:
按照网上说的,在Manifest中对应的Activity设置android:configChanges="orientation"就可以了,但是我试了半天还是不行。原来从API等级13开始还要再加一个"screenSize"才可以,即:android:configChanges="orientation|screenSize",至于在java代码中的onConfigurationChanged方法是没有要求一定要重载的,如果纯粹为了禁止onDestroy() -> onCreate()仅需要添加一句android:configChanges="orientation|screenSize"就可以了。
e.g.
AndroidManifest.xml
<activity
    android:name=".MyActivity"
    android:configChanges="orientation|screenSize" >
</activity>
Develop Reference
"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.

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多