33

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?

qtmfld
  • 2,916
  • 2
  • 21
  • 36
B.Cakir
  • 567
  • 1
  • 5
  • 19
  • 2
    If you wish to avoid the deprecation warning, yes. They are pushing everyone to the Support Library edition of fragments across the board. – CommonsWare Apr 09 '18 at 20:43

2 Answers2

58

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.

eyadMhanna
  • 2,412
  • 3
  • 31
  • 49
1

Change your import statement from android.app.DialogFragment to androidx.fragment.app.DialogFragment

Adriaan
  • 17,741
  • 7
  • 42
  • 75
Swapnil
  • 121
  • 7