1

I am trying to develop a bitmap cache for my whole application. From what i read lru cache would be the correct choice.

My question is how can i access this cache throughout my whole app?

In the first activity i will load the bmps in the cache. I want to have access to this cache in the next activities the user will access.

I am not sure how to configure this. Do i need to create a static reference or how can i send the cache between activities? I don't have much experience in this domain so help would be appreciated.

hhh3112
  • 2,167
  • 10
  • 36
  • 55

1 Answers1

2

A static reference would work, perhaps creating a Singleton class.

You could also instead extend the Application class and store references in there as the application (Activity.getApplication()) will be the same between activities.

You would have to put into the android manifest xml the new MyApplication class

    <application
    android:name="com.example.MyApplication" ...

Though I find creating Singletons to be the easier approach. There is a discussion of the two here Singletons vs. Application Context in Android?

Community
  • 1
  • 1
kassim
  • 3,880
  • 3
  • 26
  • 27
  • And a good cache library is also available: https://github.com/JakeWharton/DiskLruCache – S.D. Aug 24 '13 at 18:20
  • yeah cache libraries are a good way to go, here's a comparison of a few https://plus.google.com/103583939320326217147/posts/bfAFC5YZ3mq - I've found UrlImageViewHelper and Picasso pretty useful in the past – kassim Aug 24 '13 at 21:28