showDialog deprecated. What's the alternative?

前端 未结 5 1820
猫巷女王i
猫巷女王i 2020-12-12 15:17

Is there something else that should be called?

showDialog(TIME_DIALOG_ID);

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

5条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-12 16:15

    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

提交回复
热议问题