tonyofrancis / Fetch

The best file downloader library for Android
https://www.meta.stackoverflow.com/tags/fetch2
Apache License 2.0
1.67k stars 344 forks source link

removeListener has bugs #653

Open zhangzhen123 opened 1 year ago

zhangzhen123 commented 1 year ago
override fun removeListener(listener: FetchListener): Fetch {
    synchronized(lock) {
        throwExceptionIfClosed()
        handlerWrapper.post {
            fetchHandler.removeListener(listener)
        }
        return this
    }
}

because it is asynchronous remove listener when the view or pager is destroy it still callback the listener if this moment has ui operation will crash

Process: com.julun.jiuliao, PID: 32210
java.lang.IllegalStateException: okText must not be null
    at com.julun.jiuliao.core.ui.dialog.GuideDownloadDialog$listener$2$1.onCompleted(GuideDownloadDialog.kt:94)
    at com.tonyodev.fetch2.fetch.ListenerCoordinator$mainListener$1$onCompleted$$inlined$synchronized$lambda$2.run(ListenerCoordinator.kt:246)
    at android.os.Handler.handleCallback(Handler.java:883)
    at android.os.Handler.dispatchMessage(Handler.java:100)
    at android.os.Looper.loop(Looper.java:230)
    at android.app.ActivityThread.main(ActivityThread.java:8051)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:526)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1034)