views:

60

answers:

1

Hi:

We are supposed to cache textual and audio data in our application until device is booted or maximum of two days, whichever happens earlier. To get a perspective on data to be cached, note that we are to store about 200 text headers containing around 10 fields, each of length 30 bytes and about 20 sound files each about a minute long.

We are getting the textual data by parsing XMLs and then we keep them in ArrayLists. The sound files are directly written inside the app storage using File I/O (and not on SDcard or Apps Cache directory).

This application is to be run on devices running Android 1.5 or later.

I understand, and please correct me if I am wrong, that we can cache the files either on SDcard or inside the application or inside applications Cache directory.

I have the following questions regarding how do we approach Caching?

  1. Should we persist the textual data in applications SQLite database or should we use Java Serialization mechanism and persist the List objects(which constitute Serializable components) inside the application?
  2. Where should we write the text data /sound files - inside application, cache or SD card?
  3. Can all of these be saved to applications cache directory? How big can the cache directory grow?
  4. Can we specify a time span to Android Runtime for which a cache is maintained? Or would we have to do this manually?

Please help and advise.

Thanks. Note: have also asked this question here.

+1  A: 
  1. SQLite db. This way you'll save memory and will be able to use CursorAdapters.
  2. Put them on SD, the internal memory is very limited
  3. I'd avoid using app cache directory at all, #2
  4. You have to compare file modification timestamps against the current timestamp yourself. I'm doing this in Application's onCreate().

I'm using

  • a custom android.intent.action.BOOT_COMPLETED receiver to init cache dir on card mount
  • a helper class for cache reads/writes/cleanups, methods for saving/restoring BitmapDrawables as PNGs, creating a MD5 hash for cached file name.
alex
Thanks for your reply Alex. A few questions:Where are the SQLite databases stored? Can we create the database on SDcard?
Samuh
1. Under a dir named after app on SD. 2. Sure. Look at `SQLiteOpenHelper` implementation, then use `SQLiteDatabase`.
alex