Android onCreate() Method called twice when device rotated. (ICS)

后端 未结 3 856
余生分开走
余生分开走 2021-01-14 05:35

I\'m developing on an android tablet application and I have to manage application orientation. I got a problem that every time when I rotate the device onCreate() will be ca

3条回答
  •  Happy的楠姐
    2021-01-14 06:40

    Caution: Beginning with Android 3.2 (API level 13), the "screen size" also changes when the device switches between portrait and landscape orientation. Thus, if you want to prevent runtime restarts due to orientation change when developing for API level 13 or higher (as declared by the minSdkVersion and targetSdkVersion attributes), you must include the "screenSize" value in addition to the "orientation" value. That is, you must declare android:configChanges="orientation|screenSize". 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).

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

提交回复
热议问题