Reputation: 1276
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);
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.
Upvotes: 3
Views: 7079
Reputation: 2025
I have no idea what setUseCaches(boolean) does... but if you want to cache Http(s) data, try using HttpResponseCache. It's very easy to setup and I believe it will do what you intended setUseCaches(boolean) to do.
http://developer.android.com/reference/android/net/http/HttpResponseCache.html
Upvotes: 1
Reputation: 1276
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
Upvotes: 2