Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android : Dialog: should I hide or dismiss

Tags:

android

dialog

I'm playing around with Dialog to create some quick views in my app (like login enter name etc)

and I'm wandering what is better: hide or dismiss.

I know what they both do but I keep wandering if it is better to just hide a Dialog and show it again when I need or to dismiss it and recreate it.

my Dialogs are small and are actually static in my code so as such I don't hold tons of instances.

So can somebody give me the pros and cons of using hide over dismiss.

like image 435
Jason Rogers Avatar asked Apr 01 '11 19:04

Jason Rogers


People also ask

How dialogs are effectively handled in an Android application?

Dialogs are normally used for notifications that should interupt the user and to perform short tasks that directly relate to the application in progress (such as a progress bar or a login prompt). The Dialog class is the base class for creating dialogs. However, you typically should not instantiate a Dialog directly.

What is the dialog in Android?

A dialog is a small window that prompts the user to make a decision or enter additional information. A dialog does not fill the screen and is normally used for modal events that require users to take an action before they can proceed.


2 Answers

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

like image 170
Joshua Pinter Avatar answered Oct 11 '22 20:10

Joshua Pinter


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.

like image 32
RoflcoptrException Avatar answered Oct 11 '22 19:10

RoflcoptrException