Aspsine / MultiThreadDownload

Android Multi-Thread Download library
908 stars 284 forks source link

出现progress=100,没有回调完成方法。 #56

Closed Charlie-cui closed 8 years ago

Charlie-cui commented 8 years ago

Hi,感谢您的辛苦付出。在onProgress方法中打log显示progress=100,但是此时没有调用onCompleted方法。看到方法中存在synchronized代码块,但是没有分析出来原因。以下是我在onProgress中的规避方法。

// 处理有的下载在progress为100时不调用onComplete方法的问题
if (progress == 100) {
    if (mDownloadItem == null) {
        return;
    }
    final Long originId = mDownloadItem.getId();
    mHandler.postDelayed(new Runnable() {
        @Override
        public void run() {
            // 当前progress为100时,5秒钟后判断当前item是否还是之前的,如果是手动调用onCompleted()。
            if (originId != null && mDownloadItem != null && mDownloadItem.getId().equals(originId)) {
                logger.info("exception data!!! it's still in onProgress 5s,deal it manually");
                try {
                    onCompleted();
                } catch (RemoteException e) {
                    e.printStackTrace();
                }
            }
        }
    }, 5000);
}