最近我在我的项目中使用了 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.core的LoadAndDisplayImageTask中。那么在什么情况下会抛出这个异常,互联网链接速度不佳,设备内存不足,CPU繁忙或其他任何情况?