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
?
This class was deprecated in API level 28. Use the Support Library DialogFragment for consistent behavior across all devices and access to Lifecycle.
Dialog: A dialog is a small window that prompts the user to make a decision or enter additional information. DialogFragment: A DialogFragment is a special fragment subclass that is designed for creating and hosting dialogs.
DialogFragment is a utility class which extends the Fragment class. It is a part of the v4 support library and is used to display an overlay modal window within an activity that floats on top of the rest of the content. Essentially a DialogFragment displays a Dialog but inside a Fragment.
This is gonna be disappointing to you "great" finding but just call progressDialog. showDialog() twice back-to-back and you will get two dialogs. Because show is asynchronous and your findFragmentByTag(TAG) == null check will be true until dialog is actually added by system.
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
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With