showDialog deprecated. What's the alternative?

android, dialog

Solution

From http://developer.android.com/reference/android/app/Activity.html

public final void showDialog (int id) Added in API level 1

This method was deprecated in API level 13. Use the new DialogFragment class with FragmentManager instead; this is also available on older platforms through the Android compatibility package.

Simple version of showDialog(int, Bundle) that does not take any arguments. Simply calls showDialog(int, Bundle) with null arguments.

Why

- A fragment that displays a dialog window, floating on top of its activity's window. This fragment contains a Dialog object, which it displays as appropriate based on the fragment's state. 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.

- Here is a nice discussion Android DialogFragment vs Dialog

- Another nice discussion DialogFragment advantages over AlertDialog

How to solve?

- http://android-developers.blogspot.in/2012/05/using-dialogfragments.html

More

- http://developer.android.com/guide/topics/fundamentals/fragments.html

- http://developer.android.com/training/basics/fragments/index.html

Problem

Is there something else that should be called? ``` showDialog(TIME_DIALOG_ID); ``` It's in this tutorial but says deprecated in Eclipse.

Original source

Related problems