If you are using a DialogFragment, from what I can tell the right way to do it is to override onCancel()
I noticed setOnCancelListener does not work, and setOnKeyListener works, but for me has the fun side effect that it swallows all keys if your dialog has an edit text.