1

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 ?

Music Monkey
  • 340
  • 4
  • 15
Adam Varhegyi
  • 11,307
  • 33
  • 124
  • 222

2 Answers2

2

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.

Carnal
  • 21,744
  • 6
  • 60
  • 75
1

In Android hide() a AlertDialog means simply making it disappear from screen. But, still it is retained and attached with the Context. So, you need to call dismiss() or cancel() method to detach from the Context. Otherwise, it will give a "Leaked Window Error".

Rahul Raina
  • 3,322
  • 25
  • 30