File tree Expand file tree Collapse file tree
library/src/main/java/com/hjq/toast Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -105,8 +105,7 @@ public IToast createToast(ToastParams params) {
105105 Settings .canDrawOverlays (mApplication )) {
106106 // 如果有悬浮窗权限,就开启全局的 Toast
107107 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 )) {
110109 // 如果没有悬浮窗权限,就开启一个依附于 Activity 的 Toast
111110 toast = new ActivityToast (foregroundActivity );
112111 } else if (Build .VERSION .SDK_INT == Build .VERSION_CODES .N_MR1 ) {
@@ -314,4 +313,22 @@ protected boolean areNotificationsEnabled(Context context) {
314313 protected Activity getForegroundActivity () {
315314 return ActivityStack .getInstance ().getForegroundActivity ();
316315 }
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+ }
317334}
You can’t perform that action at this time.
0 commit comments