I have this custom dialog:
public class MyProgressDialog extends Dialog {
public MyProgressDialog(Context context) {
super(context);
}
public static MyProgressDialog show(Context context) {
MyProgressDialog dialog = new MyProgressDialog(context);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.progress);
dialog.getWindow().setBackgroundDrawableResource(
android.R.color.transparent);
dialog.show();
return dialog;
}
public static void dismiss(Context context) {
MyProgressDialog dialog = new MyProgressDialog(context);
dialog.dismiss();
}
}
It will show
protected void onPreExecute() {
MyProgressDialog.show(ItemsActivity.this);
}
but will not dismiss with:
MyProgressDialog.dismiss(ItemsActivity.this);
does anyone know why?
You’re creating a new dialog and dismissing that, not the one you created in
show(). You can keep a reference to the latest dialog created and dismiss that if you’d like. For example:However, this doesn’t seem like an ideal design.