Search code examples
androidandroid-dialogfragment

Destroy DialogFragment on onCreateDialog()


I have a dialog fragment that initializes Google plus views, sometimes those views fail so I'd like to kill the dialog at that point, before it's displayed to the user.

How can I end the dialog creation process? returning null from onCreateDialog which returns a Dialog object crushes the program.


Solution

  • If you'd like to dismiss DialogFragment within onCreateDialog you can do the following:

    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {
        setShowsDialog(false);
        dismiss();
        return null;
    }
    

    No need to override onActivityCreated().