Question

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 ?

Was it helpful?

Solution

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.

OTHER TIPS

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".

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top