2

I have an very old Android app that I am trying to update to use current libraries. Now I am trying to use the Jetpack preference library instead of the old support preference library. I have a really complicated setting hierarchy and it made sense to use the preference headers in the old library. My main settings activity subclasses PreferenceActivity and override onBuildHeaders() to load a defined list of preference headers.

There just does not seem to be any equivalent functionality in the new Jetpack preference library. It does not seem possible that Google could drop such a widely used feature without raising howls of protest, but I have been unable to find any documentation on how to migrate preference headers to Jetpack, or anyone complaining about the lack of such support. What am I missing?

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
kencorbin
  • 1,958
  • 1
  • 20
  • 18
  • Do `PreferenceCategory`s suit your use case? https://developer.android.com/reference/androidx/preference/PreferenceCategory.html. For modern grouping practices, see https://source.android.com/devices/tech/settings/settings-guidelines#grouping_dividers – stkent Feb 04 '20 at 16:49
  • Not really. A list of PreferenceScreens would come closer. But that would not turn into a split screen header / preference combination on tables. Worse, it would force me to merge all of the preference hierarchy back into on xml file, and to combine all of the nicely segregated fragments handling different preference classes into one giant fragment class. Is there a way to build a PreferenceScreen that opens a new preference hiearchy with a new fragment? That would do what I want. – kencorbin Feb 06 '20 at 19:06
  • 1
    Did you ever resolve this? I too am trying to port over old Preference headers to use androidx. – Stealth Rabbi May 28 '20 at 11:23
  • I have implemented some sort of breadcrumbs in Fulguris settings. Somewhat a mess but seems to be working now with complex hierarchy and responsive dual pane. See: https://github.com/Slion/Fulguris – Slion Aug 01 '23 at 23:01

1 Answers1

0

There is no need to support the old preference headers implementation because now, with the new Jetpack preference library, any preference anywhere can launch a new Preference fragment which will open a new preference screen.

kencorbin
  • 1,958
  • 1
  • 20
  • 18
  • Can you expand on this a bit? I don't understand. "any preference anywhere can launch a new Preference fragment which will open a new preference screen" – Stealth Rabbi May 28 '20 at 11:23
  • 1
    With the old preference headers, you were limited to a two level preference screen hierarchy. With the androidx libraries, your preference screen hierarchy can be as complicated as you like. Any single preference at any level can declare an app:fragment fragment class. Clicking on that preference will start the specified fragment which can launch it's own preference screen. It is all explained in detail at https://developer.android.com/guide/topics/ui/settings/organize-your-settings – kencorbin May 29 '20 at 13:44