What is best way to remove ProgressDialog

Posted by Sunil Kumar Sahoo on Stack Overflow See other posts from Stack Overflow or by Sunil Kumar Sahoo
Published on 2011-11-29T11:20:39Z Indexed on 2012/06/30 3:16 UTC
Read the original article Hit count: 299

Filed under:

I have created a progress dialog by

ProgressDialog progressDialog = null; // create instance variable of ProgressDialog
int dialogID = 1;
//to create progress dialog

protected Dialog onCreateDialog(int id) {
progressDialog = new ProgressDialog(context);
progressDialog.setMessage(message);
progressDialog.setIcon(android.R.id.icon);
return progressDialog;
}

// to show progressdialog 
showDialog(dialogID);

To remove the dialog I am able to use any of the following three approaches

approach-1

if(progressDialog != null){
progressDialog.dismiss();
}

approach-2

if(progressDialog != null){
    progressDialog.cancel();
    }

approach-3

removeDialog(dialogID);

I found second approach is more effective than first approach. and if I have to use with more than one progressdialog it is easier to use approach-3. But what is the best way to destroy a progressdialog and How?

© Stack Overflow or respective owner

Related posts about android