Xoundboy Xoundboy - 5 months ago 30
Android Question

What does appending uiMode to android:configChanges actually do?

I just fixed a bug in our application. The problem was that docking or undocking the device causes the application to restart. The fix, which I found after trawling loads of forum threads, was to append uiMode to the android:configChanges attribute in the AndroidManifest.xml file:

<activity android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|uiMode" android:label="@string/activity_name" android:launchMode="singleTop" android:name="MainActivity" android:theme="@android:style/Theme.Black.NoTitleBar" android:windowSoftInputMode="adjustPan">
<intent-filter android:label="@string/launcher_name">
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />

I want to be sure that by committing this change that I'm not going to break some other important functionality. As I understand it this prevents our application from being restarted upon docking or undocking. But is that all? I can't find any easy to understand documentation.


Adding something to the android:configChanges tells Android that you will handle the specific events yourself in onConfigurationChanged in the Activity class (or ignore them). If you specify something there Android won't do anything itself in case of an event being triggered which would be the Activity recreation in case of docking/undocking.

In the normal case you don't break anything as long as you don't change your layout for example in case of such an event.