DialogFragment Class Deprecated in Android P-ThrowExceptions

Exception or error:

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?

How to solve:

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.

Leave a Reply

Your email address will not be published. Required fields are marked *