diff --git a/app/src/main/java/com/gh/download/DownloadManager.java b/app/src/main/java/com/gh/download/DownloadManager.java index 5a3366313c..81eb5daf23 100644 --- a/app/src/main/java/com/gh/download/DownloadManager.java +++ b/app/src/main/java/com/gh/download/DownloadManager.java @@ -996,19 +996,21 @@ public class DownloadManager implements DownloadStatusListener { * 3.检查是否显示下载通知栏 */ public void initDownloadService() { - final Set urlSet = NDataChanger.INSTANCE.getDownloadingTaskUrlSet(); - for (DownloadEntity downloadEntity : getAllDownloadEntity()) { - if (!urlSet.contains(downloadEntity.getUrl()) - && (downloadEntity.getStatus().equals(DownloadStatus.downloading) - || downloadEntity.getStatus().equals(DownloadStatus.waiting))) { - downloadEntity.setStatus(DownloadStatus.subscribe); - mDownloadDao.newOrUpdate(downloadEntity); - NDataChanger.INSTANCE.notifyDataChanged(downloadEntity); + packageExecutor.execute(() -> { + final Set urlSet = NDataChanger.INSTANCE.getDownloadingTaskUrlSet(); + for (DownloadEntity downloadEntity : getAllDownloadEntity()) { + if (!urlSet.contains(downloadEntity.getUrl()) + && (downloadEntity.getStatus().equals(DownloadStatus.downloading) + || downloadEntity.getStatus().equals(DownloadStatus.waiting))) { + downloadEntity.setStatus(DownloadStatus.subscribe); + mDownloadDao.newOrUpdate(downloadEntity); + NDataChanger.INSTANCE.notifyDataChanged(downloadEntity); + } } - } - startDownloadService(); - checkAndRetryDownload(true); + startDownloadService(); + checkAndRetryDownload(true); + }); } /** diff --git a/app/src/main/java/com/gh/gamecenter/MainActivity.java b/app/src/main/java/com/gh/gamecenter/MainActivity.java index 2afaa1c9f5..29c7e02c55 100644 --- a/app/src/main/java/com/gh/gamecenter/MainActivity.java +++ b/app/src/main/java/com/gh/gamecenter/MainActivity.java @@ -255,9 +255,6 @@ public class MainActivity extends BaseActivity { } } - // 必须放在这里,否则会导致获取 baseActivity 不是本应用包名 - DownloadManager.getInstance().initDownloadService(); - ReservationRepository.refreshReservations(); // 跳转至其它页面 diff --git a/app/src/main/java/com/gh/gamecenter/hud/ResumeDownloadHudHandler.kt b/app/src/main/java/com/gh/gamecenter/hud/ResumeDownloadHudHandler.kt index 01c1733339..b20540b739 100644 --- a/app/src/main/java/com/gh/gamecenter/hud/ResumeDownloadHudHandler.kt +++ b/app/src/main/java/com/gh/gamecenter/hud/ResumeDownloadHudHandler.kt @@ -20,6 +20,10 @@ class ResumeDownloadHudHandler(priority: Int) : PriorityChainHandler(priority) { val isOnWiFiNetwork: Boolean = NetworkUtils.isWifiConnected(HaloApp.getInstance()) val downloadingEntitySnapshotList = DownloadManager.getInstance().allDownloadEntitySnapshots.filter { it.status == DownloadStatus.downloading + || it.status == DownloadStatus.pause + || it.status == DownloadStatus.subscribe + || it.status == DownloadStatus.timeout + || it.status == DownloadStatus.neterror } if (!isOnWiFiNetwork || downloadingEntitySnapshotList.isEmpty()) { diff --git a/app/src/main/java/com/halo/assistant/HaloApp.java b/app/src/main/java/com/halo/assistant/HaloApp.java index dc340584f1..5efb2837e9 100644 --- a/app/src/main/java/com/halo/assistant/HaloApp.java +++ b/app/src/main/java/com/halo/assistant/HaloApp.java @@ -364,6 +364,9 @@ public class HaloApp extends MultiDexApplication { // 必须放在外面,否则不能及时刷新用户数据 UserRepository.getInstance().getLoginUserInfo(); + // 初始化下载服务,恢复下载任务 + DownloadManager.getInstance().initDownloadService(); + GlobalPriorityChainHelper.INSTANCE.preStart(isNewForThisVersion); MainWrapperRepository.Companion.getInstance().getDataUnion();