Search code examples
androidandroid-fragmentsandroid-preferencesappcompatactivity

Android: AppCompatPreferenceActivity as a Fragment


I implemented my preferenceActivity with extending AppCompatPreferenceActivity. But now I got a tablayout and I would like to get this preference screen inside this tablayout. The easiest way would be to have this preference activity as a fragment.

Does anyone know how I can achieve this? What is the best practice for using AppCompatPreferenceActivity for Fragments?


Solution

  • You can migrate most of the code to PreferenceFragment.

    Keep in mind fragments themselves are not as robust as Activities, if you have multiple PreferenceScreens, You might need to implement extra logic to navigate between those as specified in the documentation.