triniwiz / nativescript-downloader

Apache License 2.0
32 stars 18 forks source link

Crashing in worker #55

Open DanglSan opened 3 years ago

DanglSan commented 3 years ago

If the demo apps cannot help and there is no issue for your problem, tell us about it

Downloader crashes when it is running in worker

Which platform(s) does your issue occur on?

Please, provide the following version numbers that your issue occurs with:

Please, tell us how to recreate the issue in as much detail as possible.

Just run downloader.start(...) in worker.

Is there any code involved?

const downloader = new Downloader();
const imageDownloaderId = downloader.createDownload({
    url: "https://.../....zip",
    path: folderPath,
    fileName: "1.zip"
});

downloader.start(imageDownloaderId, (progressData: ProgressEventData) => {
        console.log(`Progress : ${progressData.value}%`);
        console.log(`Current Size : ${progressData.currentSize}%`);
        console.log(`Total Size : ${progressData.totalSize}%`);
        console.log(`Download Speed in bytes : ${progressData.speed}%`);
    })
    .then((completed: DownloadEventData) => {
        console.log(`Image : ${completed.path}`);
    })
    .catch((error) => {
        console.log(error.message);
    });

if I run this code in main thread all is ok, but when I run it in worker I got such error:

System.err: An uncaught Exception occurred on "main" thread.
System.err: Cannot find object id for instance=co.fitcom.fancydownloader.DownloadListenerUI_worker_73565_85_@2149300
System.err: StackTrace:
System.err: com.tns.NativeScriptException: Cannot find object id for instance=co.fitcom.fancydownloader.DownloadListenerUI_worker_73565_85_@2149300
System.err:     at com.tns.Runtime.callJSMethodImpl(Runtime.java:1166)
System.err:     at com.tns.Runtime.callJSMethod(Runtime.java:1160)
System.err:     at com.tns.Runtime.callJSMethod(Runtime.java:1138)
System.err:     at com.tns.Runtime.callJSMethod(Runtime.java:1134)
System.err:     at co.fitcom.fancydownloader.DownloadListenerUI_worker_73565_85_.onUIProgress(co.fitcom.fancydownloader.DownloadListenerUI.java)
System.err:     at co.fitcom.fancydownloader.DownloadListenerUI$1.handleMessage(DownloadListenerUI.java:55)
System.err:     at android.os.Handler.dispatchMessage(Handler.java:111)
System.err:     at android.os.Looper.loop(Looper.java:207)
System.err:     at android.app.ActivityThread.main(ActivityThread.java:5769)
System.err:     at java.lang.reflect.Method.invoke(Native Method)
System.err:     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
System.err:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:679)