views:

168

answers:

2

I am fetching a lot of thumbnails in my application from a remote server and lazy loading these in a list View. The image fetches run in a background AsynTask and when completed the fetched images are stored in a HashMap using SoftReferences. This works just fine but when the images in the cache gets GC'd the fetches have to be rerun.

I could have stored them on the SDcard that way there would be no re-fetching. But I did not take this approach because of the clutter it would create on the SD card. Maybe there are alternatives to these sorta like temporary folders that can be cleared when Activity/app finishes/exits?

What is the "ideal place" to cache images? Any advice,example projects or pointers appreciated.

Thanks!

+4  A: 

You should check files data storage options:
http://developer.android.com/guide/topics/data/data-storage.html
Files are being saved in the applications directory, so there is no mess anywhere. Files will be finally removed with the app. You can also implement some method which will clear the cache when the app starts (for example remove files older than 2 weeks).

Michal Dymel
+1  A: 

You should be able to locate a SQLite DB on the SD card. This would let you have a fairly clean interface/cache space while keeping data off the very limited internal phone memory. You can specify the location of the DB by calling openOrCreateDatabase(String path, SQLiteDatabase.CursorFactory factory). It may be more work than you'd like to put in, but you should be able to clear ou the DB when you application is unloaded with a line or two of code.
More from the documentation here: http://developer.android.com/reference/android/database/sqlite/SQLiteDatabase.html

haseman