0

I have the following preference screen.

<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" >
    <PreferenceCategory 
        android:title="@string/preference_about">
        <PreferenceScreen
            android:title="@string/preference_backup_restore_data"
            android:persistent="false">
            <Preference
                android:key="BACKUP"
                android:title="@string/preference_backup" />
            <Preference
                android:key="RESTORE"
                android:title="@string/preference_restore" />
        </PreferenceScreen>
        <Preference
            android:key="FAQ"
            android:title="@string/preference_faq_title" />
    </PreferenceCategory>
</PreferenceScreen>

If I went into the inner preference screen by tapping preference_backup_restore_data, and rotate my device, I will quit from the inner preference screen.

I was wondering, how can I prevent such behavior? I prefer to stay in inner preference screen, even though there is configuration change.

bwegs
  • 3,769
  • 2
  • 30
  • 33
Cheok Yan Cheng
  • 47,586
  • 132
  • 466
  • 875

1 Answers1

0

Adding android:key to PreferenceScreen will able to handle configuration change nicely.

Instead of

<PreferenceScreen
    android:title="@string/preference_backup_restore_data"
    android:persistent="false">

Use

<PreferenceScreen
    android:key="PREFERENCE_BACKUP_RESTORE_DATA"
    android:title="@string/preference_backup_restore_data"
    android:persistent="false">
Cheok Yan Cheng
  • 47,586
  • 132
  • 466
  • 875