File tree Expand file tree Collapse file tree 1 file changed +19
-2
lines changed
library/src/main/java/com/hjq/toast Expand file tree Collapse file tree 1 file changed +19
-2
lines changed Original file line number Diff line number Diff line change @@ -105,8 +105,7 @@ public IToast createToast(ToastParams params) {
105
105
Settings .canDrawOverlays (mApplication )) {
106
106
// 如果有悬浮窗权限,就开启全局的 Toast
107
107
toast = new GlobalToast (mApplication );
108
- } else if (!params .crossPageShow && foregroundActivity != null && !foregroundActivity .isFinishing () &&
109
- (VERSION .SDK_INT >= VERSION_CODES .JELLY_BEAN_MR1 && !foregroundActivity .isDestroyed ())) {
108
+ } else if (!params .crossPageShow && isActivityAvailable (foregroundActivity )) {
110
109
// 如果没有悬浮窗权限,就开启一个依附于 Activity 的 Toast
111
110
toast = new ActivityToast (foregroundActivity );
112
111
} else if (Build .VERSION .SDK_INT == Build .VERSION_CODES .N_MR1 ) {
@@ -314,4 +313,22 @@ protected boolean areNotificationsEnabled(Context context) {
314
313
protected Activity getForegroundActivity () {
315
314
return ActivityStack .getInstance ().getForegroundActivity ();
316
315
}
316
+
317
+ /**
318
+ * Activity 是否可用
319
+ */
320
+ protected boolean isActivityAvailable (Activity activity ) {
321
+ if (activity == null ) {
322
+ return false ;
323
+ }
324
+
325
+ if (activity .isFinishing ()) {
326
+ return false ;
327
+ }
328
+
329
+ if (VERSION .SDK_INT >= VERSION_CODES .JELLY_BEAN_MR1 ) {
330
+ return !activity .isDestroyed ();
331
+ }
332
+ return true ;
333
+ }
317
334
}
You can’t perform that action at this time.
0 commit comments