add synchronized to onDismiss to avoid null pointer exception