【发布时间】:2014-03-11 22:16:52
【问题描述】:
我正在使用 Android Volley 库,如果您知道的话,我的问题应该很容易回答;)。
我需要知道com.android.volley.toolbox.ImageLoader.ImageListener 在
处理成功的响应。文档说
The call flow is this: 1. Upon being attached to a request,
onResponse(response, true) will be invoked to reflect any cached data
that was already available. If the data was available, response.getBitmap() will
be non-null. 2. After a network response returns, only one of the following
cases will happen: - onResponse(response, false) will be called if the
image was loaded. or - onErrorResponse will be called if there was an error
loading the image.
我想知道的是:这是否意味着我可以将onResponse 调用两次(首先将isImmediate 设置为false,然后设置为true)?我可以依靠吗?我的意思是会一直这样(如果图片加载成功的话)?
我正在尝试做这样的事情
imageLoader.get(image.getUrl(), new ImageListener() {
@Override
public void onErrorResponse(VolleyError error) {
callback.call(null, error);
}
@Override
public void onResponse(ImageContainer response,
boolean isImmediate) {
if (response.getBitmap() != null) {
callback.call(response.getBitmap(), null);
}
}
});
当图像可以成功加载时,我需要调用callback.call(),并且我还需要response.getBitmap() 来返回实际位图而不是null。
提前致谢!
【问题讨论】:
标签: android caching request response android-volley