gpt4 book ai didi

Android Volley ImageListener onResponse 行为

转载 作者:行者123 更新时间:2023-11-29 01:44:24 26 4
gpt4 key购买 nike

我正在使用 Android Volley Library,我的问题应该很容易回答,如果你知道 ;)。

我需要知道 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() 返回实际位图而不是

提前致谢!

最佳答案

What I want to know is this: does that mean that I can have onResponse called twice (first with isImmediate set to false and then set to true)? Can I rely on that? I mean will it always be like this (if the image loading is succesful)?

简短回答:

除非更改此类的实现(而且我非常怀疑会发生这种情况),否则您可以依赖此调用顺序。

如果有帮助,我在此处的另一个答案中详细介绍了三种可能的响应情况:https://stackoverflow.com/a/32464875/3227795

关于Android Volley ImageListener onResponse 行为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22337854/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com