AppCompatDialog vs DialogFragment
Asked Answered
P

1

6

With the latest AppCompat

compile "com.android.support:appcompat-v7:22.2.1"

There is both available AppCompatDialog and DialogFragment which one should I prefer are there any differences or problems that can I avoid?

Edit:

I tried to use either the AppCompatDialog or DialogFragment by converting an existing Dialog that I had, but in none the getDialog().setTitle("Title") seem to work.

Philips answered 26/8, 2015 at 13:58 Comment(1)
The [DialogFragment][1] and the [AppCompatDialog][2] are completely different.[1]: developer.android.com/reference/android/support/v4/app/… [2]: developer.android.com/reference/android/support/v7/app/…Pelagianism
P
-1

Update 17 May 2021:

Quoting from Android Documentation:

A dialog is a small window that prompts the user to make a decision or enter additional information. A dialog does not fill the screen and is normally used for modal events that require users to take an action before they can proceed.

You should use a DialogFragment as a container for your dialog. The DialogFragment class provides all the controls you need to create your dialog and manage its appearance, instead of calling methods on the Dialog object.

Using DialogFragment to manage the dialog ensures that it correctly handles lifecycle events such as when the user presses the Back button or rotates the screen. The DialogFragment class also allows you to reuse the dialog's UI as an embeddable component in a larger UI, just like a traditional Fragment (such as when you want the dialog UI to appear differently on large and small screens).

Note: AppCompatDialog is a Dialog extension.


Previous answer (Nov 16 '19):

The DialogFragment and the AppCompatDialog are completely different.


As per Gabriele Mariotti comment.

Philips answered 16/11, 2019 at 12:21 Comment(1)
what is the different ?Manchu

© 2022 - 2024 — McMap. All rights reserved.