Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Usage of android.support.v4.app or android.app for DialogFragment?

Reading through official documentation of Android made me little bit confused about this 2 libraries. When should I use one and when the other one?

As far as I'm understanding, it's the best to use Android Support library depending to the number of devices that will be able to run it and the look will stay always the same. No matter what might get in the future of the android, Support library will always be supported on any future Android API. But why is then DialogFragment for android.app? It is logic to me that android.app.DialogFragment has some benefits which that from support's doesn't because anyways it would be useless to have it, since it's not supported on so many devices.

Can you help me which I should prefer to use it and if my sayings were right?

like image 871
Tommz Avatar asked Sep 03 '13 09:09

Tommz


People also ask

How to use DialogFragment in android?

To create a DialogFragment , first create a class that extends DialogFragment , and override onCreateDialog() , as shown in the following example. Similar to how onCreateView() should create a root View in an ordinary fragment, onCreateDialog() should create a Dialog to display as part of the DialogFragment .

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.

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.

How to close DialogFragment?

tl;dr: The correct way to close a DialogFragment is to use dismiss() directly on the DialogFragment. Control of the dialog (deciding when to show, hide, dismiss it) should be done through the API here, not with direct calls on the dialog. Dismiss the fragment and its dialog.


1 Answers

If your app needs to be compatible with Android 2.x you should use the DialogFragment from the Support Library. Notice that adding the Support Library to your project makes your app bigger because the JAR of the Support Library will be included in your APK.

If you only support Android 3.x or higher you can stick with the DialogFragment built-in into the OS.

Both versions of the API offer (roughly) the same functionality.

like image 62
Litrik De Roy Avatar answered Sep 21 '22 06:09

Litrik De Roy