PRDownloader
PRDownloader copied to clipboard
How to resume a download request after app restart
I'm trying to resume a download request after the app is killed. I tried doing it by persisting the download Id like this
taskId = request!!.start(object : OnDownloadListener {
override fun onDownloadComplete() {
Timber.d("Video completed!")
videoComplete = true
notifyComplete()
}
override fun onError(error: Error?) {
videoComplete = false
notifyError(error)
}
})
And then saving the taskId
to a file.
After the app is restarted I retrieve the taskId
from the file and use it like this:
PRDownloader.resume(taskId!!)
After debugging I figured out that the download request is null and therefore the request isn't resumed.
public void resume(int downloadId) {
DownloadRequest request = currentRequestMap.get(downloadId);
if (request != null) { // it's null!
request.setStatus(Status.QUEUED);
request.setFuture(Core.getInstance()
.getExecutorSupplier()
.forDownloadTasks()
.submit(new DownloadRunnable(request)));
}
}
Any help would be appreciated. Thanks!
I also verified that prdownloader.db
has an entry with the taskId
after kill application. The PRDownloader.getStatus(downloadId) alway return UNKOWN. I enabled database in config. how to implement this case? please help.
this occurred also for me in app kill and in connection broken given that the database is active but downloaded size temp file cleans Check yourself once - when download starting turn off internet