How to cancel or dismiss a custom dialog in its onCreate method?
You should place the logic to determine if the dialog is to be shown outside of the onCreate()
method. it does not belong there.
Alternatively, rename your show()
method showIfRequired()
(or something), and add the conditional show logic there.
I know this doesn't technically answer your question, but what you are trying to do is not the correct design. That's a good thing, as doing in the right way is actually simpler.
Also, as a side note, you should using DialogFragment in favor of Dialog
. it's available in the v4 support library.