title: Getting ClassCastException on PreferenceManager.setDefaultValues()
body: <p>I am getting this exception  </p>
  
  <blockquote>
    <p>Caused by: java.lang.ClassCastException: androidx.preference.PreferenceScreen cannot be cast to android.preference.GenericInflater$Parent</p>
  </blockquote>
  
  <p>on doing  <code>PreferenceManager.setDefaultValues(this, R.xml.root_preferences, false);</code><br>
  in the main activity. </p>
  
  <p>According to <a href="https://stackoverflow.com/questions/21215830/android-preferences-classcastexception">this</a> SO post, the above error can happen if in the manifest file the activity and its parent is same but that is not the case with me. I just don't get why this exception is thrown. </p>
  
  <p><strong>AndroidManifest.xml</strong>  </p>
  
  <pre><code>         &lt;activity
                  android:name=".SettingsActivity"
                  android:label="@string/title_activity_settings"
                  android:parentActivityName=".MainActivity"&gt;
                  &lt;meta-data
                      android:name="android.support.PARENT_ACTIVITY"
                      android:value="com.example.android.droidcafeinput.MainActivity" /&gt;
              &lt;/activity&gt;
          &lt;activity
              android:name=".MainActivity"
              android:label="@string/app_name"
              android:theme="@style/AppTheme.NoActionBar"&gt;
              &lt;intent-filter&gt;
                  &lt;action android:name="android.intent.action.MAIN" /&gt;
  
                  &lt;category android:name="android.intent.category.LAUNCHER" /&gt;
              &lt;/intent-filter&gt;
          &lt;/activity&gt;
  </code></pre>
  
  <p><strong>root_preferences.xml</strong></p>
  
  <pre><code>&lt;androidx.preference.PreferenceScreen xmlns:app="http://schemas.android.com/apk/res-auto"&gt;
  
      &lt;PreferenceCategory app:title="@string/messages_header"&gt;
  
          &lt;EditTextPreference
              app:key="signature"
              app:title="@string/signature_title"
              app:useSimpleSummaryProvider="true" /&gt;
  
          &lt;ListPreference
              app:defaultValue="reply"
              app:entries="@array/reply_entries"
              app:entryValues="@array/reply_values"
              app:key="reply"
              app:title="@string/reply_title"
              app:useSimpleSummaryProvider="true" /&gt;
  
      &lt;/PreferenceCategory&gt;
  
      &lt;PreferenceCategory app:title="@string/sync_header"&gt;
  
          &lt;SwitchPreferenceCompat
              app:key="sync"
              app:title="@string/sync_title" /&gt;
  
          &lt;SwitchPreferenceCompat
              app:dependency="sync"
              app:key="attachment"
              app:summaryOff="@string/attachment_summary_off"
              app:summaryOn="@string/attachment_summary_on"
              app:title="@string/attachment_title" /&gt;
  
      &lt;/PreferenceCategory&gt;
  
  &lt;/androidx.preference.PreferenceScreen&gt;
  </code></pre>
  
  <p><strong>SettingsActivity.java</strong></p>
  
  <pre><code>public class SettingsActivity extends AppCompatActivity {
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.settings_activity);
          getSupportFragmentManager()
                  .beginTransaction()
                  .replace(R.id.settings, new SettingsFragment())
                  .commit();
          ActionBar actionBar = getSupportActionBar();
          if (actionBar != null) {
              actionBar.setDisplayHomeAsUpEnabled(true);
          }
      }
  
      public static class SettingsFragment extends PreferenceFragmentCompat {
          @Override
          public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
              setPreferencesFromResource(R.xml.root_preferences, rootKey);
          }
      }
  }
  </code></pre>
  
  <p><strong>Stacktrace</strong>  </p>
  
  <pre><code>Caused by: Java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.android.droidcafeinput/com.example.android.droidcafeinput.MainActivity}: java.lang.ClassCastException: androidx.preference.PreferenceScreen cannot be cast to android.preference.GenericInflater$Parent
          at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2817)
          at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2892)
          at android.app.ActivityThread.-wrap11(Unknown Source:0)
          at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1593)
          at android.os.Handler.dispatchMessage(Handler.java:105)
          at android.os.Looper.loop(Looper.java:164)
          at android.app.ActivityThread.main(ActivityThread.java:6541)
          at java.lang.reflect.Method.invoke(Native Method)
          at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
          at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
       Caused by: java.lang.ClassCastException: androidx.preference.PreferenceScreen cannot be cast to android.preference.GenericInflater$Parent
          at android.preference.GenericInflater.inflate(GenericInflater.java:321)
          at android.preference.GenericInflater.inflate(GenericInflater.java:264)
          at android.preference.PreferenceManager.inflateFromResource(PreferenceManager.java:324)
          at android.preference.PreferenceManager.setDefaultValues(PreferenceManager.java:650)
          at android.preference.PreferenceManager.setDefaultValues(PreferenceManager.java:609)
          at com.example.android.droidcafeinput.MainActivity.onCreate(MainActivity.java:74)
          at android.app.Activity.performCreate(Activity.java:6975)
          at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1213)
          at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2770)
          at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2892) 
          at android.app.ActivityThread.-wrap11(Unknown Source:0) 
          at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1593) 
          at android.os.Handler.dispatchMessage(Handler.java:105) 
          at android.os.Looper.loop(Looper.java:164) 
          at android.app.ActivityThread.main(ActivityThread.java:6541) 
          at java.lang.reflect.Method.invoke(Native Method) 
          at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240) 
          at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
  </code></pre>