I am unclear how images are handled in Android in terms of caching.
Let's say, I have an app that is 3 levels deep (so, it has 3 Activities that are pushed on top of each other).
If each of my 3 activities shows 3 images in the ToolBar of all 3 Activities, my understanding is that the same 3 images are going to be loaded in memory 3 times. This is resulting in 9 images taking memory although it is really only 3 images, they are just loaded multiple times.
Also, let's say my main activity has a ListView showing information about documents retrieved over the network.
Each list view item is customized to show 3 pieces of information:
- an image representing a type of document (i.e. .txt, .pdf, .docx, .js, ...)
- a string representing a title
- a string representing some description
If the above ListView loads million items (each represents a document) and assume all are a word document, then all million images for .docx type are downloaded but it really is just one image that I need. This seem to be obvious waste of network bandwidth and memory, I'd like to download only one image and use it million times rather than download million images and use them each only once.
So, in scenario like this, where I dont know what kind of image I will need and therefore do not have it in image assets but rely on downloaded image to show document type, is there some kind of caching strategy that I could use to avoid having to download same image million times?
Is it provided by Android already?
UPDATE
In my above example of Toolbar images, these are Android Resource images (so, drawables). So, for these, I believe these are cached by default?
However, the ListView images are images that are downloaded from the web, so in my example above with custom ListViewItem consisting of 3 Views (one Image and 2 Labels), the Image would be downloaded at the same time ListView is being rendered. I am providing a simple ListView item with only 3 Views but it could be 10 views (say 4 images and 6 Labels). The main point is that the one image is downloaded from the web during the rendering process of the ListView. Since that image might be repeating, how to awoid downloading same image but to use cached one?