Prevent Android activity dialog from closing on outside touch

Fergusmac picture Fergusmac · Aug 24, 2012 · Viewed 177.6k times · Source

I have an activity that is using the Theme.Dialog style such that it is a floating window over another activity. However, when I click outside the dialog window (on the background activity), the dialog closes. How can I stop this behaviour?

Answer

Singhak picture Singhak · Sep 28, 2013

To prevent dialog box from getting dismissed on back key pressed use this

dialog.setCancelable(false);

And to prevent dialog box from getting dismissed on outside touch use this

 dialog.setCanceledOnTouchOutside(false);