Adam Varhegyi Adam Varhegyi - 9 months ago 47
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);
alt_bld.setMessage(message)
.setCancelable(false)
.setPositiveButton("OK", new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface dialog, int id)
{


ProgressDialog dialog1 = ProgressDialog.show(CombatActivity.this, "Loading",
"Pushing OK...", true);


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



}
});

AlertDialog alert = alt_bld.create();
// Title for AlertDialog
alert.setTitle("Nyertél.");
// Icon for AlertDialog
alert.setIcon(R.drawable.icon);
alert.show();


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