On Jul 5, 5:26 pm, doles <[email protected]> wrote: > Hello, > > How is in-memory caching achieved in android? For example, i have static > data such as state list in the United States. I would like to keep that list > in a file or somewhere in an online service. However, when the app is > running, I'd rather store in memory in the app itself. How is that achieved? > I could create a singleton and initialize that on startup. What are the best > practices if any? Thank you for reading and responding!
Have a look at WeakReference, SoftReference and WeakHashMap classes in Android API. WeakHashMap would be the simplest, but not too practical in memory cache. If you could build SoftHashMap (no such class in Android API) which once you understand the principles is not that hard, you would have quite decent in-memory object cache. It would be purged only on low-memory events by the system. Upon retrieval, you have to detect cache-miss, then retrieve the object and store in your cache as well. Daniel -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en

