I have android application which deals with lot of progress dialogs.I have to create a separate dialog for each activity.
Dialog creation takes a activity(context) as parameter while constructing.
Is there a way by which I can create a single dialog (which is tied to application and not the activity) and show it in different activity so that I do not have to create it repeatedly.
Declare showProgressDialog
and hideProgressDialog
in Utill helper class as shown in following code snippet
public static ProgressDialog showProgressDialog(Context context) {
ProgressDialog pDialog = new ProgressDialog(context);
pDialog.setMessage("Please wait...");
pDialog.setCancelable(false);
pDialog.show();
return pDialog;
}
public static void hideProgressDialog(ProgressDialog pDialog) {
if (pDialog.isShowing())
pDialog.dismiss();
}
Then call from activity where you need to show the ProgressDialog for example in onPreExecute()
method of AsyncTask class as shown in below code snippet
ProgressDialog pDialog = Util.showProgressDialog(this);
and use following code to hide the progressDialog
Util.hideProgressDialog(pDialog);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With