Kill DialogFragment on onCreateDialog ()

I have a fragment of a dialog that initializes the Google plus views, sometimes these views fail, so I would like to kill the dialog at this point before it is displayed to the user.

How can I finish the process of creating a dialogue? returning null from onCreateDialog, which returns a Dialog object, suppresses the program.

+4
source share
2 answers

If you want to remove DialogFragment inside onCreateDialog, you can do the following:

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

No need to override onActivityCreated ().

+3
source

Solved it with the onActivityCreated() Fragment callback, which is called after OnCreateDialog() . I am returning a valid dialog from OnCreateDialog() , but a flag with dismiss that the dialog should be rejected.

 public void onActivityCreated (Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); if(dismiss) { this.dismiss(); } } 
+3
source

Source: https://habr.com/ru/post/1493120/


All Articles