PRDownloader icon indicating copy to clipboard operation
PRDownloader copied to clipboard

How to resume a download request after app restart

Open omarsahl opened this issue 6 years ago • 3 comments

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!

omarsahl avatar Sep 09 '18 15:09 omarsahl

I also verified that prdownloader.db has an entry with the taskId

omarsahl avatar Sep 09 '18 15:09 omarsahl

after kill application. The PRDownloader.getStatus(downloadId) alway return UNKOWN. I enabled database in config. how to implement this case? please help.

kakapro32 avatar Sep 16 '18 10:09 kakapro32

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

MS0054 avatar Dec 06 '20 20:12 MS0054