Android : Dialog: should I hide or dismiss
I know that It is a very old post but I've found none of the answers above good enough, so in the simplest way of explaining:
hide()
will just change the visibility status of the dialog but the object will be still there and can be shown again usingshow()
method.dismiss()
hides and also destroys the dialog. To show the dialog again it needs to be recreated first.
Then if you need to show and hide a dialog many times better to hide()
it. eventually dismiss()
it on onDestroy()
to avoid the window leak error. Note that leaving the activity when a dialog not dismissed causes the memory leak.
hope it will be useful for feature references.
Using hide()
could cause a Leaked Window
error.
If you choose to use hide()
and you exit your application using finish()
, this will cause an error message (seen here) about a window being leaked.
So, either dismiss()
your dialogs properly before calling finish()
or just use dismiss()
instead of hide()
.
It depends on how many time your need it, and if it is expensive to create it. If it is not too expensive to create it, I would personally prefer to dismiss it, to have a "cleaner environment". But if you're not using hundreds of dialogs, I don't think this really matters.