views:

49

answers:

2

Hi. I have an application, which on the onResume() method takes some time to redraw. I want to cache some things, but I am unfamiliar how and what can I "cache" (preload) data and keep it when my app is not visible.

My question is - I have some data and I want it to be loaded in memory when my activity is not visible. My data is actually a little set of jpeg'. Problem - they are being redrawn.

How can I achieve that? Strategy, example with very simple things, anything would be very useful to me.

Thanks in advance.

A: 

I don't know if I am right about your question, this is my understanding: you want to preload images(from url or sd card or somewhere else), and you want the loading to be done before the acitvity is visible to user.

I don't think there is anyway you can "preload" image or something else, since you don't know when will user resume your app. So, I think you can start an thread(or AsyncTask, I think this is an better way) to load resources in your Activity's onResume method. While loading, you can show an progress dialog or something to info user it is loading, dismiss the dialog and show the content when you are done with loading.

Tony
A: 

You might look into whirlycache, it is quite fast.

Whirlycache is a fast, configurable in-memory object cache for Java. It can be used, for example, to speed up a website or an application by caching objects that would otherwise have to be created by querying a database or by another expensive procedure. From the testing that we have done, it appears to be faster than any other Java cache that we have been able to inspect.

You will need to port over some of the code to Android since it is not 100% Android compatible (e.g. the logging is based on log4j), but this should be fairly straightforward.

aprock