Since the Android getFragmentManager() API is deprecated, is there any alternative?

前端 未结 12 1551
梦毁少年i
梦毁少年i 2020-12-05 06:47

FragmentManager is deprecated. Is there an alternative or what can I do now?

 PlaceAutocompleteFragment autocompleteFragment = (PlaceAutocomplet         


        
12条回答
  •  孤城傲影
    2020-12-05 07:20

    If you're displaying a DialogFragment over a PreferenceFragment (specifically an android.preference.PreferenceFragment not the class from the Support Preference library), then you will see this warning.

    Approximately June 2018, Google deprecated the PreferenceFragment and all its associated methods like getFragmentManager(). You probably already know that getSupportFragmentManager() cannot be used on the PreferenceFragment anyway, as it's a special exception.

    The recommended approach now is to use the PreferenceFragmentCompat from the AndroidX Jetpack library or from the Preference Support library:

    implementation "androidx.preference:preference:1.0.0"
    

    You can see available versions here: https://maven.google.com -> Search for "preference"

    More info here: Android- deprecated method warning regarding PreferenceActivity


    Be aware that migrating to PreferenceFragmentCompat may be a lengthy and difficult task, especially if you have custom Preference classes. More info:

    • How do I create custom preferences using android.support.v7.preference library?
    • https://github.com/jaredrummler/ColorPicker/issues/26#issuecomment-331626888
    • https://issuetracker.google.com/issues/119256512
    • https://issuetracker.google.com/issues/124153118
    • Android: How to remove margin/padding in Preference Screen

提交回复
热议问题