的URLConnection和setUseCaches(真) [英] URLConnection and setUseCaches(true)

查看:118
本文介绍了的URLConnection和setUseCaches(真)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是当前code下载线程中的图像:

I am using the current code to download images in a thread:

Log.d(TAG, "Fetching image: " + BASE_URL + mURL);

URLConnection connection;
InputStream   input;

connection = (new URL(BASE_URL + mURL)).openConnection();
connection.setUseCaches(true);
connection.connect();
input = connection.getInputStream();

Bitmap image = BitmapFactory.decodeStream(input);

借助 Android文档是不是如果setUseCaches很清楚()方法将缓存中的数据。从测试它看起来并不像它是,但我想知道如果我做错了什么,如果有人知道,如果setUseCaches()做任何事情。

The Android documentation is not very clear if the setUseCaches() method will cache the data. From testing it doesn't look like it is, but I wanted to know if I was doing something wrong of if anyone knows if setUseCaches() does anything.

推荐答案

据我所知,使用setUseCaches(真)没有任何影响,不缓存任何东西。缓存在Android文件的推荐方法是将文件写入专用内部存储和使用getCacheDir()方法:

As far as I can tell, using setUseCaches(true) has no effect and does not cache anything. The recommended way to cache files on Android is to write files to private internal storage and to use the getCacheDir() method:

http://developer.android.com/guide/topics/data/data-storage.html#filesInternal

这篇关于的URLConnection和setUseCaches(真)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆