Close dialogs along with activities

Replaces #396