0

I have a listview with title and image in one row. And image is to come from remote server. Whats the best way to cache those images in android. I could think of two ways.

  1. Cache image on sdcard and corresponding entry in sqlite so that I can get path while listview is being scrolled.

  2. Cache images per activity so if activity finishes. Image cache flushes

Point 2 is simpler but not efficient.

How will be the performance in point 1.

Please help and suggest any other alternatives.

Rahul
  • 1,403
  • 4
  • 18
  • 31
  • 1
    Take a look at [this excellent piece of code](http://stackoverflow.com/questions/541966/android-how-do-i-do-a-lazy-load-of-images-in-listview/3068012#3068012) to lazy-load the images and cache them in SD card. Really inspiring – maid450 Jan 14 '11 at 10:43
  • but if there is no SD card in device? – Sameer Z. Jul 05 '11 at 06:42
  • this code is meant to be used as an example that you can customize. I suppose you can modify it to write to internal storage in the device, but this is not a very good place for massive storage like cache of pictures... – maid450 Jul 06 '11 at 10:17

1 Answers1

3

The answer is: it depends. You need to know if the application is going to access files on web every time you open an activity, and you need to know if the server images change frequently or not.

I think option 1 is a good option if images don't change frequently, and option 2 is a good option if images change frequently.

For more information, read this: http://developer.android.com/training/displaying-bitmaps/index.html

Tiago Almeida
  • 14,081
  • 3
  • 67
  • 82
Valter Júnior
  • 948
  • 7
  • 19