Ravi Parmar
Ravi Parmar

Reputation: 1018

When to use PreferenceFragment and PreferenceFragmentCompat?

I am just a beginner but i have some questions regarding the support library.

  1. Every time google team add's a new Support version it deprecated the use in new Version, so because of this we have to redo the code again just to support new API level.Can't it be like this , you can have this library but you will be not getting extra features .Instead of just deprecating the entire work ? Because of this there is a lot of extra work to do while making android app.
  2. Why was PreferenceFragment deprecated in Android P and what are the support versions for both libraries PreferenceFragment and PreferenceFragmentCompat also what addition features to do you get?

Android platform is amazing but it's difficult to understand this things . If a developer has made an app what is the guaranty it will work when android releases new version ? With every release something is deprecated either the feature or the whole library.

Upvotes: 5

Views: 2514

Answers (1)

CommonsWare
CommonsWare

Reputation: 1007322

Every time google team add's a new Support version it deprecated the use in new Version, so because of this we have to redo the code again just to support new API level.

That is not the case. "Deprecated" in Android usually means "we have something that we would prefer that you use". So, while eventually you should try to move off of deprecated APIs, "eventually" could be on the order of a couple of years.

Why was PreferenceFragment deprecated in Android P

The native android.preference.PreferenceFragment was deprecated in Android 9.0, mostly because it inherits from android.app.Fragment, which was deprecated in Android 9.0. The fragment code has had lots of bugs over the years. Google is trying to steer developers towards using a library-supplied fragment implementation, as the libraries can be kept up to date, while older Android devices (unfortunately) do not get updates.

There is nothing stopping you from using android.preference.PreferenceFragment in Android 9.0 if you wish. Ideally, over time, you stop using it, but you do not need to drop everything and change your code tomorrow.

what are the support versions for both libraries PreferenceFragment and PreferenceFragmentCompat

AFAIK android.support.v14.preference.PreferenceFragment should also be marked as deprecated, as it too inherits from android.app.Fragment.

android.support.v7.preference.PreferenceFragmentCompat extends from android.support.v4.app.Fragment, and so AFAIK this is the one that you should be using in the short term.

The whole preference fragment stuff is a bit of a mess at the moment — I am hoping that Google settles this out and provides clearer instructions as part of the migration to androidx over the next few months.

Upvotes: 4

Related Questions