[ACCEPTED]-How to check is a dialog opened or not ?-android

Accepted answer
Score: 36

You should put this code in every activity 1 that you want to support this feature.

public AlertDialog myAlertDialog;

public void showDialog(Context context) {
        if( myAlertDialog != null && myAlertDialog.isShowing() ) return;

        AlertDialog.Builder builder = new AlertDialog.Builder(context);
        builder.setTitle("Title");
        builder.setMessage("Message");
        builder.setPositiveButton("ok", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int arg1) {
                    dialog.dismiss();
                }});
        builder.setCancelable(false);
        myAlertDialog = builder.create();
        myAlertDialog.show();
}
Score: 1

Rewrite your method to return AlertDialog, assign it 6 to a member and check before invoking this 5 method if it's null or !isShowing().
You could also 4 use onCreateDialog instead. Implement this method in base 3 class for your activities that needs the 2 dialog managing and then call showDialog(int id) wherever 1 you want.

More Related questions