Adam Varhegyi Adam Varhegyi -3 years ago 155
Android Question

When shall I call dimiss() or hide() in my Dialogs?

I got this dialog snipet:

String message="This will be my message";

AlertDialog.Builder alt_bld = new AlertDialog.Builder(this);
.setPositiveButton("OK", new DialogInterface.OnClickListener()
public void onClick(DialogInterface dialog, int id)

ProgressDialog dialog1 =, "Loading",
"Pushing OK...", true);

Intent i = new Intent();
i.setClass(MyFirstActivity.this, MySecondActivity.class);


AlertDialog alert = alt_bld.create();
// Title for AlertDialog
// Icon for AlertDialog

My question is:
Should i call .hide() or .dismiss() in any of these ?
The message text will be dynamicly read, and I dont want a separate instance for every shown dialog. I just want only one with updated messages.

So how and when should i call remove or dismiss ?

Answer Source

Yeah, you have to call dismiss() before you call finish(), otherwise the dialog will remain in the background and can cause problem when you try to start other activities.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download