Several Activity
s in my app display images in a ListView
where each row of the ListView
contains an ImageView
.
An example of this would be a search screen where the user searches, gets results, and a picture of each result is shown.
I'm trying to weigh the cost/benefits of implementing a global LruCache
vs having each Activity
contain its own local LruCache
.
Here are my two main problems. Both revolve around the fact that my app is quite large, meaning there are quite a few screens which show these images. Also, my app has the popular side menu way of navigating. Because of this, I could open the menu, tap Activity B
, open the menu, tap Activity A
, open the menu... etc. and create an Activity
stack of ABABABABABABABAB indefinitely.
Global
Won't Activity
s with ImageView
s using Bitmap
s from a global LruCache
contain references to these Bitmaps
? Suppose the user navigates away from this Activity
by clicking some Button
. That Activity
is now on the Activity
stack and still holds references to those Bitmaps
. If the LruCache
pops a Bitmap
off, can that Bitmap
really be reclaimed when an ImageView
in some Activity
on the stack holds a reference to it?
I had previously created my own custom cache. If I called recycle()
on a Bitmap
and then the user hit the back button to go back to some Activity
on the stack that contained an ImageView
set to that Bitmap
, the app would crash. This is why I believe ImageView
s on Activity
s on the stack still hold references to Bitmap
s.
Local
As I mentioned earlier. My app is quite large, and side menu style of navigation allows the user to create rather large Activity
stacks. This would create a lot of LruCache
s. And, since you have to declare the size of the LruCache
when you initialize it, there wouldn't seem to be any good way of picking a size.
Thoughts? Suggestions?
At this point I think I have to do global, but I don't know how to solve the Activity
stack reference problem. I can't imagine this isn't a problem many apps haven't run into. I don't know why I'm not finding information about it.