Fix #2357. Close progress dialog when ending activity

This corrects errors of leaking the dialog.