【问题标题】:Universal Image Loader - Not caching URL 404通用图像加载器 - 不缓存 URL 404
【发布时间】:2013-12-17 10:46:41
【问题描述】:

基于此讨论: Universal Image Loader - Image URL 404 Error handling

我制作图像加载器。它工作正常! 但在我的情况下,服务器上删除的图像文件已过期。我希望为此缓存的查询 URL 404,但没有缓存,并且每次我在此待处理的图像 URL 中向下滚动列表视图以获取 404 时都会发生。它是如何缓存的?

【问题讨论】:

    标签: android universal-image-loader


    【解决方案1】:

    这是一个很晚的答案,但它会帮助别人,答案只是在这里解释,

    DisplayImageOptions options = new DisplayImageOptions.Builder()
                .resetViewBeforeLoading(false).delayBeforeLoading(10)
                .showImageOnFail(null).showImageForEmptyUri(null) // this will intitate null if there is loading fail or empty url
                .cacheInMemory(true).cacheOnDisc(true).handler(new Handler())
                .build();
    

    并使用此处理 404

        ImgLoader.displayImage(Globals.Image_Domain + largeimageUrl,
                    largeImage, Base.options, new ImageLoadingListener() {
    
                        @Override
                        public void onLoadingStarted(String imageUri, View view) {
                        }
    
                        @Override
                        public void onLoadingFailed(String imageUri, View view,
                                FailReason failReason) {
                            // TODO Auto-generated method stub
                            // This will handle 404 and it will catch null exception
                            // do here what you want to do 
                        }
    
                        @Override
                        public void onLoadingComplete(String imageUri,
                                View view, Bitmap loadedImage) {
                            // TODO Auto-generated method stub
                            if (largeImage == null)
                                return;
    
                            largeImage.setImageBitmap(loadedImage);
                        }
    
                        @Override
                        public void onLoadingCancelled(String imageUri,
                                View view) {
                        }
    
                    });
    

    【讨论】:

    • 在什么意义上这是一个解决方案? onLoadingFailed 怎么办才会被缓存?
    • 在这种情况下你应该使用.showImageOnFail(anydrawable).showImageForEmptyUri(anydrawable)
    • 我已经设置了,但是下次它仍然会尝试从 url 重新加载图像。
    猜你喜欢
    • 2013-05-02
    • 2016-02-29
    • 2014-10-14
    • 1970-01-01
    • 2015-06-20
    • 2015-04-02
    • 2014-06-16
    • 2014-01-14
    • 2014-01-19
    相关资源
    最近更新 更多