Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PreferenceFragment Deprecated

For creating settings page I used PreferenceFragment in my older project. But PreferenceFragment is deprecated in Android API level 28.

What will be alternative of PreferenceFragment now?

like image 310
Yeahia2508 Avatar asked Nov 30 '25 02:11

Yeahia2508


1 Answers

Instead of using PreferenceFragment now we have to use PreferenceFragmentCompat

Implementation example inside Fragment:

public static class DemoFragment extends PreferenceFragmentCompat {

    @Override
        public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
        // Load the preferences from an XML resource
        setPreferencesFromResource(R.xml.preferences, rootKey);
    }
}

Please see official documentation of PreferenceFragmentCompat.

like image 97
Yeahia2508 Avatar answered Dec 01 '25 17:12

Yeahia2508



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!