Persisting Images - Design Query

by Brian » Fri, 30 Apr 2010 15:57:55 GMT


Sponsored Links
 Hi guys,
I'm new enough to Android development and am still getting to grips
with the framework. I'm building a simple application that will
display some products where each product will have a name, description
and an image.

I'm using SQLite to persist the product data and have found that
pretty straight forward so far. My question is around design and
finding the best practice to solve my problem.

My question is as follows...

Where should I store the images (.png files) that are shipped with the
application?

Given my basic knowledge I see a couple of options here
1. Store them in the res/drawable folder and access them as standard
resources e.g. R.drawable.image_name
2. Store them in the res/asset folder and access them using an
InputStream. This way I could store a URI in the database for each
image pointing to the file in the asset directory.

These approaches are fine if the data remains static, however we want
to add functionality where we will download new product data to the
device from the web.
When we download this data we can persist the name and description
part in the database (no problems here) but I'm not sure what to do
with the images. We cannot add these new images to the asset directory
with the existing images as the asset directory cannot be written to
at runtime. As far as I am concerned I have two options here

1. Use the MEDIA content provider to persist the image on the device
internal data store and store the image URI in the database to
identify the path to an image.
OR
2. Create a folder on the file system and write my new image files to
this folder. Then store the file path in the product database to
identify an image (Not 100%
sure this is possible, can someone please confirm)

The problem with both these approaches is that there is an
inconsistency between how my initial product images are stored and how
the downloaded image updates are stored. This seems like poor design,
to have your initial images in one place (res/asset) and your
downloaded image updates persisted using the MEDIA content provder.

I need advice on how best to approach this in terms of good clean
design and best practice. I dont need specific code examples as I can
figure out the implmentation myself once I've discovered what approach
to take.

Apologies for the long post but I've been looking at this for a few
days now and have been doing quite a bit of head scratching. I'd like
to start my Andorid development off using best practices so I was
hoping some of the more experienced guys could assist.

Thanks
Brian

--



Other Threads

1. image capture and get both the original image and a thumbnail

hi
i want to take a picture with camera, after read the document and googling,I 
found,
if i don't want the original picture,i just use 

Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(intent, CAPTURE_PICTURE_CODE);

to start the camera activity, and in  
onActivityResult(int requestCode, int resultCode,Intent intent)  method,i can 
get the thumbnail from the intent .

and if i want the original picture ,i use this 

Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(getTempImageFile()));
startActivityForResult(intent, CAPTURE_PICTURE_CODE);

to start the camera activity, 
and in onActivityResult(int requestCode, int resultCode,Intent intent) , i can 
get the original picture with 

Bitmap bm = BitmapFactory.decodeFile(getTempImageFile().getAbsolutePath());

but in this case ,the intent variable is null ,so i can't get the thumbnail.

so is there an easy way to get both the thumbnail and the original picture ?

if the only way is to use the Camera class ,and make my own camera activity ,is 
there any example code ? or is there any Camera-relative open source project ?

thanks 

-- 

2. Soft Keyboard Control

Is there a way to get the soft keyboard to come up in the same mode as
it was left the last time it was brought up.  For example, if the user
had switched to entering numbers, is there a way to set it up so that
the next time he brings up the keyboard, it will default to entering
numbers?

Failing that, is there some way to control the current input mode
(e.g. alpha or numbers) for the keyboard?

Thanks.

-- 

3. websockets in webkit

4. Checksum Java function in Android

5. Independent Wallpapers on Multiple Screens

6. how to use Opengl 2.0 on android?

7. onBind and unBind questions