Cancel dialog before finishing activity to prevent leaking window.