There are two ways of closing an alert dialog.
Option 1:
AlertDialog#create().dismiss();
Option 2:
The DialogInterface#dismiss();
Out of the box, the framework calls DialogInterface#dismiss();
when you define event listeners for the buttons:
AlertDialog#setNegativeButton();
AlertDialog#setPositiveButton();
AlertDialog#setNeutralButton();
for the Alert dialog.