Search code examples
androidandroid-preferencespreferencefragment

Missing FragmentFactory class and getFragmentFactory() method in FragmentManager


I'm trying to implement a hierarchical multi-screen settings for my app. I'm following the "Organize your settings" guide, which contains an example implementation of a function that should construct a new Fragment instance using the FragmentFactory class:

val fragment = supportFragmentManager.fragmentFactory.instantiate(
        classLoader,
        pref.fragment,
        args)

However, the IDE cannot resolve neither this class or the fragmentFactory property of FragmentManager.

I'm using the following support libraries:

implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'androidx.coordinatorlayout:coordinatorlayout:1.0.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.lifecycle:lifecycle-extensions:2.0.0'
implementation 'androidx.preference:preference:1.0.0'
implementation 'androidx.fragment:fragment-ktx:1.0.0'

Is it possible that the guide refers to not-yet-stable features?


Solution

  • Turns out this class is available in androidx.fragment since version 1.1.0. Currently it's still in alpha and I'm only using stable lib versions for production.