我正在使用android凌空图书馆,如果您知道,我的问题应该很容易回答;)。
我需要知道 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
。
预先感谢!
我想知道的是:这是否意味着我可以使用两次响应(首先将Isimmediate设置为false,然后设置为true)?我可以依靠吗?我的意思是总是这样(如果图像加载是成功的)?
简短答案:是。
除非更改此类的实施(我高度怀疑会发生),否则您可以依靠此呼叫顺序。
如果有帮助,我在此处的另一个答案中对三个可能的响应案例进行了一些详细信息:https://stackoverflow.com/a/32464875/32227795