views:

91

answers:

1

Hi all,

I'm just looking for some insight into what would be the best way for me to store images as part of my app.

I have an activity that represents a 'Job' which has a couple of edittext's and underneath was planning on using the Gallery component to show images relevant to this job.

The job data is stored in a database (on the sdcard) so was also thinking of creating a table to store 'JobImages' and having each image stored as a byte array.

But I'm not sure if it would be better to store the images directly on sdcard under a folder structure specific to my application and the job. E.g. using the job ID number as a folder name.

Depending on which method I use will greatly determine the code that goes into an 'adapter' that allows me to bind to the gallery component so before I begin I was wondering if anyone has had the same design problem and what option they chose.

Thanks,

Dave

A: 

Regardless of what storage method you choose, don't let that stop you from writing the code that will use it. Write a class that abstracts this from your app and just gives you images, how/where it retrieves images from, doesn't matter, this will also help you in the future if you decide to change your storage method, you will only have to change this class, not the whole app.

Back to the original question, it depends how you'll be using the images, if you already have a db and need to associate the images with other records or add additional properties (i.e. a database of animals in a shelter with their pictures and other attributes), makes sense to store in a db. If all you care about are pictures that don't have any need to be organized (i.e. the built in Gallery), then store in a folder.

Here's a link on how to store in DB: http://www.helloandroid.com/tutorials/store-imagesfiles-database

Ricardo Villamil
THanks for your response, Although I have a db, since it's stored on the sd card, it removes my initial concern of storing images on the sdcard and 'what if' the user removes the card...So I'll have a go and create a class that uses media storage as it must be faster than encoding/decoding byte arrays to the DB. I do hope however that if I store the images in a custom folder for my app they don't appear in the stock gallery application, I'd rather they remain accessible only from my application.
Dave