// Create a dialog builder AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle("Alert Dialog"); builder.setMessage("This is an example of an Alert Dialog"); // Set the OnDismissListener builder.setOnDismissListener(new DialogInterface.OnDismissListener() { @Override public void onDismiss(DialogInterface dialogInterface) { // Code to be executed when the dialog is dismissed Log.d("DismissListener", "Dialog dismissed"); } }); // Create and show the dialog AlertDialog dialog = builder.create(); dialog.show();In this example, we create an Alert Dialog with a title and message. We then set an OnDismissListener which logs a message when the dialog is dismissed. Finally, we create and show the dialog. The package library for this class is android.app.