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

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.
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.



Other Threads

1. Strange Disappearances


Androidology - Part 1 of 3 - Architecture Overview

In one of these 3 Videos I remember Mike Cleron saying that he thinks
what will be Popular for Android is the combo of Location, Maps, RPC,
etc. to create Mashups. Now I don't see where he says that, as if it's
been edited out.



On the Developer Roadmap it says there will be an announcement
regarding ADC II. But I don't remember hearing anything. Neither did
anyone ask why there wasn't any mention of it.

Q4 2008 - Key Announcement on Android Developer Challenge II



In August this was on the Android Developers Blog. I haven't heard
more on it.

"One of our top priorities after the first devices ship is to develop
a device-to-device (and possibly device-to-server) RPC mechanism that
is fast, reliable, and protective of developers and users alike."


- Juan T.

2. Does anyone use the Browser on their G

I am wondering if people use the G1's built-in browser regularly and
substantially. I always find it too slow, and the pages are too hard to
navigate. I found the iPhone's browser to be slightly better, but it's still
not a pleasant user experience.

But, maybe I am just too picky. Do you use the G1's Browser regularly? If
so, what sites do you read? How many stars would you rate it?



3. Editing XML files using DOM in Android

4. Android design question

5. startActivityForResult problems

6. SSL client authentication

7. What's the bar at the top of the screen called?