fix bugs.
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package com.xscm.moduleutil.dialog;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.Activity;
|
||||
import android.app.Dialog;
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
@@ -36,6 +37,7 @@ public class ConfirmDialog extends Dialog {
|
||||
private int countdownSeconds = 0; // 倒计时秒数
|
||||
private CountDownTimer countDownTimer; // 倒计时对象
|
||||
|
||||
private Context context;
|
||||
|
||||
public ConfirmDialog(Context context, String title, String message,
|
||||
String positiveButtonText, String negativeButtonText,
|
||||
@@ -43,6 +45,7 @@ public class ConfirmDialog extends Dialog {
|
||||
View.OnClickListener negativeButtonClickListener,
|
||||
boolean isCountdownEnabled, int countdownSeconds) {
|
||||
super(context);
|
||||
this.context = context;
|
||||
this.title = title;
|
||||
this.message = message;
|
||||
this.positiveButtonText = positiveButtonText;
|
||||
@@ -60,6 +63,7 @@ public class ConfirmDialog extends Dialog {
|
||||
View.OnClickListener negativeButtonClickListener,
|
||||
boolean isCountdownEnabled, int countdownSeconds) {
|
||||
super(context);
|
||||
this.context = context;
|
||||
this.title = title;
|
||||
this.spannableMessage = spannableMessage;
|
||||
this.positiveButtonText = positiveButtonText;
|
||||
@@ -178,6 +182,12 @@ public class ConfirmDialog extends Dialog {
|
||||
countDownTimer.cancel(); // 取消倒计时
|
||||
countDownTimer = null;
|
||||
}
|
||||
if (context instanceof Activity) {
|
||||
Activity activity = (Activity) context;
|
||||
if (activity.isFinishing() || activity.isDestroyed()) {
|
||||
return; // Don't try to dismiss if activity is gone
|
||||
}
|
||||
}
|
||||
super.dismiss();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user