download-manager icon indicating copy to clipboard operation
download-manager copied to clipboard

DownloadManager in androidx.work.Worker

Open maciej-wichrowski opened this issue 5 years ago • 1 comments

What we have tried to achive is to run a download manager void delete(DownloadBatchId downloadBatchId) from androidx.work.Worker. It seems to have been working sucessfully but when app goes to background (or is killed) then on some devices there are frequent occurances of:

Fatal Exception: java.lang.NullPointerException: Attempt to invoke virtual method 'void com.novoda.downloadmanager.eb.a(com.novoda.downloadmanager.u)' on a null object reference at com.novoda.downloadmanager.DownloadManagerBuilder$1.onServiceConnected(DownloadManagerBuilder.java:252) at android.app.LoadedApk$ServiceDispatcher.doConnected(LoadedApk.java:1223) at android.app.LoadedApk$ServiceDispatcher$RunConnection.run(LoadedApk.java:1240) at android.os.Handler.handleCallback(Handler.java:739) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:148) at android.app.ActivityThread.main(ActivityThread.java:5417) at java.lang.reflect.Method.invoke(Method.java) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)

It seems that the application is waken up properly and it is crashing on initializing the DownloadManager

`class AutoDeleteWorker @AssistedInject constructor( // assisted annotated names MUST exactly match those in the ChildWorkerFactory!!!!! @Assisted context: Context, @Assisted params: WorkerParameters, private val downloadRepository: DownloadRepository, private val downloadInteractor: DownloadInteractor ) : Worker(context, params) {

override fun doWork(): Result {
    //trigger  downloadInteractor.delete(downloadId)
    return Result.success()
}

@AssistedInject.Factory
interface Factory : ChildWorkerFactory

}`

Is there already a working solution to trigger the downloadManager from worker?

maciej-wichrowski avatar Jun 05 '19 13:06 maciej-wichrowski

looks like https://github.com/novoda/download-manager/pull/513 should have fixed this issue 🤞

ouchadam avatar Sep 26 '19 07:09 ouchadam