Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 955
Aviran Avatar asked Jul 24 '13 06:07

Aviran


2 Answers

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().

like image 76
jazzgil Avatar answered Sep 24 '22 02:09

jazzgil


Solved it using the onActivityCreated() Fragment callback which is called after OnCreateDialog(). I return a valid Dialog from onCreateDialog() but flag with dismiss that the dialog should be dismissed.

public void onActivityCreated (Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    if(dismiss) {
        this.dismiss();
    }
}
like image 39
Aviran Avatar answered Sep 25 '22 02:09

Aviran