Search code examples
androidandroid-activitylifecycle

onDestroy is called on rotation despite configChanges setting


I have added configChanges option to activity description because I want to handle screen rotation events in onConfigurationChanged. Here is excerpt from activity config

<activity
  android:name=".MainActivity"
  android:configChanges="keyboardHidden|orientation"
  android:label="@string/title_activity_main">

  .........

</activity>

But despite the setting activity is destroyed anyway on every screen rotation.

Is this expected behavior? I read elsewhere that configuration changes should not cause activity destroy if this change is in activity's configChanges.

Am I better not using onConfigurationChange and instead optimize for onDestroy/onCreate sequence?


Solution

  • As of Android 3.2, you also need to add "screenSize":

    android:configChanges="keyboardHidden|orientation|screenSize"
    

    Source: http://developer.android.com/guide/topics/resources/runtime-changes.html#HandlingTheChange