How to cancel or dismiss a custom dialog in its onCreate method?

Viewed 2757

I have created a custom dialog called MyCustomDialog which extends Dialog. I create and show my custom dialog as follows:

new MyCustomDialog(myContext).show();

I override the Dialog.onCreate(Bundle savedInstanceState) method to do my initialisation. I also check in this method whether a certain condition holds and, if not, I would like to dismiss/cancel my dialog. I have tried calling the cancel() and dismiss() methods in my dialog's onCreate(Bundle savedInstanceState) and onStart() methods but it has no effect.

Anyone know how to cancel or dismiss a dialog (from within the dialog) before it shows?

2 Answers
Related