반응형

A라는 Activity에서 화면 회전등의 변경이 일어날 때 메모리에 저장된 데이터를 유지하기 위하여 Manifest에서 해당 Activity에 다음과 같은 속성을 설정했다.


android:configChanges="orientation"


기본적으로 이 설정은 잘 동작하지만, 보통 추천하는 설정은 다음과 같다.


android:configChanges="orientation|keyboardHidden"


GB 소스를 참고해서 만들고 있었기 때문에 몰랐었던 내용이었는데, 위 설정에도 불구하고 JB MR2에서 onConfigurationChanged() 가 호출되지 않고 onSavedIns...() -> onDestroy() -> onCreate() 과정의 메서드가 호출이 되었다.


안드로이드 개발 사이트를 뒤적여보니 다음과 같은 내용이 있었다. (출처 : http://developer.android.com/guide/topics/resources/runtime-changes.html)


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 targetSdkVersionattributes), you must include the "screenSize" value in addition to the "orientation" value. That is, you must decalare 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).


최종적으로 다음과 같이 설정하니 잘 동작한다.


android:configChanges="orientation|keyboardHidden|screenSize"


+ Recent posts