diff --git a/app/src/main/java/com/gh/ndownload/NDownloadService.java b/app/src/main/java/com/gh/ndownload/NDownloadService.java index 28750eabcf..4bdfbe9dc7 100644 --- a/app/src/main/java/com/gh/ndownload/NDownloadService.java +++ b/app/src/main/java/com/gh/ndownload/NDownloadService.java @@ -14,9 +14,11 @@ import android.text.TextUtils; import androidx.annotation.Nullable; import androidx.core.app.NotificationCompat; +import com.blankj.utilcode.util.ThreadUtils; import com.gh.download.DownloadManager; import com.gh.gamecenter.SplashScreenActivity; import com.gh.gamecenter.common.base.GlobalActivityManager; +import com.gh.gamecenter.core.AppExecutor; import com.gh.ndownload.suspendwindow.NDownloadDrawOverlayPermissionWindowController; import com.gh.ndownload.suspendwindow.NDownloadSuspendWindowController; import com.gh.ndownload.suspendwindow.utils.NDownloadSuspendWindowHelper; @@ -282,6 +284,14 @@ public class NDownloadService extends Service { } private void showDownloadSuspendWindowIfNeeded(DownloadEntity entry) { + if (ThreadUtils.isMainThread()) { + showDownloadSuspendWindowIfNeededInner(entry); + } else { + AppExecutor.getUiExecutor().execute(() -> showDownloadSuspendWindowIfNeededInner(entry)); + } + } + + private void showDownloadSuspendWindowIfNeededInner(DownloadEntity entry) { if (!NDownloadSuspendWindowHelper.shouldSkipDownloadEntity(getApplicationContext(), entry)) { if (NDownloadSuspendWindowHelper.canDrawOverLayer(getApplicationContext())) {// 已开启悬浮窗权限,直接显示悬浮窗 showDownloadSuspendWindow();