1

最近我在我的项目中使用了 UIL 的 Release 1.9.1 并且我的测试人员反复反馈说,当应用程序第一次启动时图像没有显示,但是当应用程序启动或完成之后就可以了。然后我检查日志,logcat 显示“任务被中断”。然后我在源代码中找到了 InterruptedException 段。原始代码是:

/** @return true - if task should be interrupted; false - otherwise */
private boolean waitIfPaused() {
    AtomicBoolean pause = engine.getPause();
    synchronized (pause) {
        if (pause.get()) {
            log(LOG_WAITING_FOR_RESUME);
            try {
                pause.wait();
            } catch (InterruptedException e) {
                L.e(LOG_TASK_INTERRUPTED, memoryCacheKey);
                return true;
            }
            log(LOG_RESUME_AFTER_PAUSE);
        }
    }
    return checkTaskIsNotActual();
}

/** @return true - if task should be interrupted; false - otherwise */
private boolean delayIfNeed() {
    if (options.shouldDelayBeforeLoading()) {
        log(LOG_DELAY_BEFORE_LOADING, options.getDelayBeforeLoading(), memoryCacheKey);
        try {
            Thread.sleep(options.getDelayBeforeLoading());
        } catch (InterruptedException e) {
            L.e(LOG_TASK_INTERRUPTED, memoryCacheKey);
            return true;
        }
        return checkTaskIsNotActual();
    }
    return false;
}

此代码段位于com.nostra13.universalimageloader.coreLoadAndDisplayImageTask中。那么在什么情况下会抛出这个异常,互联网链接速度不佳,设备内存不足,CPU繁忙或其他任何情况?

4

2 回答 2

1

这个问题在这里解决:https ://github.com/nostra13/Android-Universal-Image-Loader/issues/586

看起来不错。

于 2014-11-28T10:59:16.560 回答
0

我认为当您调用ImageLoader.stop()ImageLoader.destroy()系统完成应用程序时可能会发生这种情况,因此应用程序线程被中断。同时,防止同一张图片的url同时加载的synchronized语句。waitIfPaused因此,如果同时加载了一个 url,则第二个将等待第一个 pic 成功加载。

于 2015-03-18T03:57:48.133 回答