DialogFragment Class Deprecated in Android P

B.Cakir picture B.Cakir · Apr 9, 2018 · Viewed 14.7k times · Source

The Android Documentation gives the following warning.

This class was deprecated in API level P. Use the Support Library DialogFragment for consistent behavior across all devices and access to Lifecycle.

Does this simply mean that the only change for me as a developer is to import android.support.v4.app.DialogFragment instead of the old android.app.DialogFragment?

Answer

eyadMhanna picture eyadMhanna · Apr 10, 2018

Google is encouraging all developers to shift from the ordinary DialogFragment to the support version of the same class, you can still use the deprecated version of course but if Google recommends the support version, why wouldn't you?

Simply change your import statement from android.app.DialogFragment to android.support.v4.app.DialogFragment.

Also, consider changing all the imports if you are using the deprecated version of normal fragments.

UPDATE

If you are using the brand new AndroidX library instead of the old support library change it to androidx.fragment.app.DialogFragment but pay attention about how you are using the DialogFragment in your code because you have to migrate also to the new androidx.fragment.app.FragmentActivity.