you can move this check into the if since activity is only null if dialog is null