Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is best way to remove ProgressDialog

Tags:

android

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?

like image 901
Sunil Kumar Sahoo Avatar asked Nov 29 '11 11:11

Sunil Kumar Sahoo


2 Answers

cancel(); is better than dismiss() because according to docs:

Cancel the dialog. This is essentially the same as calling dismiss(), but it will also call your DialogInterface.OnCancelListener (if registered).

removeDialog() is deprecated so that would be the worst way.

like image 126
Caner Avatar answered Oct 12 '22 23:10

Caner


I think below way is the best to dismiss the progress bar from screen:

if(progressDialog.isShowing())
{
   progressDialog.dismiss();
}
like image 41
Paresh Mayani Avatar answered Oct 12 '22 22:10

Paresh Mayani