Android截击ImageListener响应行为
我使用的是安卓截击库,如果您知道的话,我的问题应该很容易回答;) 我需要知道Android截击ImageListener响应行为,android,caching,request,response,android-volley,Android,Caching,Request,Response,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 alrea
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
提前谢谢
我想知道的是:这是否意味着我可以调用onResponse两次(首先将isImmediate设置为false,然后设置为true)?我可以相信吗?我的意思是,它是否总是这样(如果图像加载成功)
简短回答:是
除非这个类的实现发生了改变(我非常怀疑这种情况会发生),否则您可以相信这个调用顺序会得到尊重
如果有帮助的话,我在这里的另一个答案中给出了三个可能的响应案例的一些细节: