Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DialogFragment Class Deprecated in Android P

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?

like image 982
B.Cakir Avatar asked Apr 09 '18 20:04

B.Cakir


People also ask

Is DialogFragment deprecated?

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

What is difference between dialog and DialogFragment in Android?

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.

What is DialogFragment used for?

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.

How do I know if DialogFragment is showing?

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.


1 Answers

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.

like image 55
eyadMhanna Avatar answered Sep 25 '22 11:09

eyadMhanna