Only modify and query downloads array in main thread

This fixes a ConcurrentModificationException if the thread that queues downloads (database IO)
adds the item to the downloads list and the notification updater queries the downloads list at
the same time.
This commit is contained in:
ByteHamster 2020-01-03 22:50:27 +01:00
parent 29a8a5e5aa
commit 3e8c1ee117
1 changed files with 6 additions and 6 deletions

View File

@ -477,13 +477,13 @@ public class DownloadService extends Service {
&& isEnqueued(request, itemsEnqueued)) {
request.setMediaEnqueued(true);
}
handler.post(() -> {
downloads.add(downloader);
downloadExecutor.submit(downloader);
postDownloaders();
});
}
queryDownloads();
handler.post(this::queryDownloads);
}
private static boolean isEnqueued(@NonNull DownloadRequest request,