Alister
Alister

Reputation: 6837

storing images on android

I'm developing a small Android database app. Associated with the records in the database is a number of images (the image resolution will probably same as the screen on the device), there could be up to 20 images per record. Where would be the best place to store the images. I'm thinking either in the database itself or on the SD card. I'm pretty new to Android and as yet not really sure what I'm doing.

Upvotes: 4

Views: 1497

Answers (2)

Barmaley
Barmaley

Reputation: 16363

In my application I was forced to store images in SQLite as blobs. Blob size in SQLite limited in theory by 2 gigs - but manual recommends to use only few megs sized blobs. So I'm chunking stored images. From performance point of view - everything is OK

Anyway, I'm pretty sure that image storing in DB is more attractive than other exotic ways. E.g. noone can predict capacity of SD card or even it's presence on board.

Upvotes: 3

Khalos
Khalos

Reputation: 2373

While it's possible to put the image itself in the database (as a blob) as far as I understand it's not the best practice.

How big are the images you're talking about? You said about the resolution of the screen, but with compression, they might be small enough.

If they're fairly small, consider using the phone's internal cache (found using getCacheDir() from a context). This also has the added bonus of allowing the user to delete the cache from the application menu, and your images will be private to your application. The Android documentation suggests approximately a 1MB cap on internal cache.

If they're too big to store in the internal cache, the SD card may be your only option. The downside to this is those images will be visible to other applications, they can be deleted, removed, renamed, etc. You can't guarantee they'll be the way they were when you left them.

Upvotes: 4

Related Questions