Skip to content Skip to sidebar Skip to footer

Nested Preference Screen Closes On Screenorientation Change In Android

I recently stumbled upon a problem. I am working with a Nested PreferenceScreen like this: <

Solution 1:

Got it. In order to prevent a nested screen from closing on rotation, you need to make sure the parent screen is given a key value. Thats it. Eg:

<PreferenceScreenxmlns:android="http://schemas.android.com/apk/res/android"android:key="useless_key"><PreferenceScreenandroid:key="pref_name"android:title="@string/pref_title" ></PreferenceScreen></PreferenceScreen>

Side note, though overriding onConfigChanges solved the issue, you should almost never do so. It completely changes how an Activity normally behaves. Rotation is just one of many reasons why a config change happens. If your Activity can't handle a rotation properly, then it'll also fail on handling those other conditions. Check out this insightful post for more.

Post a Comment for "Nested Preference Screen Closes On Screenorientation Change In Android"