Yousha Aleayoub
Yousha Aleayoub

Reputation: 5638

Difference between removeDialog(), dismissDialog() and dismiss()

What is different between removeDialog() and dismiss() and dismissDialog()? because I'm able to use them together without any problem.

And is it matter when implementing DialogInterface.OnClickListener or AlertDialog.OnClickListener?

I searched a lot but couldn't find anything useful.

EDIT: I'm developing for Android 2.3.

Example code:

public final class OptionsPreference extends PreferenceActivity implements DialogInterface.OnClickListener
{
private AlertDialog noInternetDialog = null;
//...

    @Override
    protected void onPause()
    {
        if (this.noInternetDialog != null)
        {
            Log.d(LOG_TAG, "Destroying noInternetDialog...");
            this.noInternetDialog.dismiss(); // X?
            removeDialog(DIALOG_NOINTERNET); // X?
            dismissDialog(DIALOG_NOINTERNET); // X?
            this.noInternetDialog = null;
        }
        super.onPause();
    }

    @Override
    protected final Dialog onCreateDialog(final int id)
    {
        switch (id)
        {
            case DIALOG_NOINTERNET:
            {
                final AlertDialog.Builder _builder = new AlertDialog.Builder(this).setIcon(android.R.drawable.ic_dialog_info).setMessage(R.string.str_nointernet);
                _builder.setCancelable(false);
                _builder.setPositiveButton(R.string.str_wifisettings, this);
                _builder.setNeutralButton(R.string.str_ok, this);
                this.noInternetDialog = _builder.create();
                if (!isFinishing())
                {
                    this.noInternetDialog.show();
                }
                return this.noInternetDialog;
            }
// ...
}

Upvotes: 3

Views: 3114

Answers (1)

Shadab Ansari
Shadab Ansari

Reputation: 7070

dismissDialog(int id) : Dismisses the dialog with the specified id. It only hides the dialog but still keeps the internal references by the Activity which contains this dialog so that it can be restored in future.Deprecated in API 13.

removeDialog(int id) : It also dismisses the dialog with the specified id. Means it hides that particular dialog and in addition cleans up all the references by the Activity and hence cannot be restored in future. Deprecated in API 13.

dismiss() : This method operates on a particular dialog because it is a method of Dialog class. It also dismisses the dialog. You have to own a valid dialog in order to dismiss it else you'll get exception.

Upvotes: 5

Related Questions