What is the best way to remove ProgressDialog

I created a run dialog

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 a dialog, I can 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 the second approach more effective than the first approach. and if I need to use more than one progress, then it is easier to use approach-3. But what is the best way to destroy progressdialog and How?

+4
source share
3 answers

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

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

removeDialog() deprecated, so this will be the worst way.

+6
source

I think the following is the best way to divert the progress bar from the screen:

 if(progressDialog.isShowing()) { progressDialog.dismiss(); } 
+1
source

Depends on what you want to achieve. If you want to create a Processdialog each time with a new message, you need to use the onPrepareDialog() method or use the removeDialog() method in the dialog shown. Since the next time you use yourDialog.show() , the onCreate() method is called again, if you just reject your dialog, it will not be called the next time you show it. onPrepareDialog() is called every time.

http://developer.android.com/guide/topics/ui/dialogs.html

0
source

Source: https://habr.com/ru/post/1383613/


All Articles