showDialog deprecated. What's the alternative?

Denis picture Denis · Apr 23, 2012 · Viewed 123k times · Source

Is there something else that should be called?

showDialog(TIME_DIALOG_ID);

It's in this tutorial but says deprecated in Eclipse.

Answer

Md Mahbubur Rahman picture Md Mahbubur Rahman · Dec 21, 2012

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?

More