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. Instrumentaion - running multiple istrumentation simultaneously

Hello All,

This is what I have,say:

TestCases : TestCase 1 to TestCase10 , all have several test methods
in it (all extends base class InstrumentationTestCase)

                    TestSuite 1 - Adds 'TestCase 1 to TestCase10' in
its suite

All of the above is in single APK.

Instrumentation Runer used is - android.test.InstrumenationTestRunner

This is what I am trying:

- I launched Emulator having above apk

- I opened three terminals , two to run instrumentation and third one
to log results i.e.

Terminal 1 : adb shell am instrument -w -e class
com.InstrTest.TestSuite1 com.InstrTest/

shortMsg=Process crashed.

Terminal 2:

terminal 1 : adb shell am instrument -w -e class
com.MyInstr.TestSuite1 com.MyInstr/

DDM dispatch reg wait timeout
Can't dispatch DDM chunk 52454151: no handler defined
Can't dispatch DDM chunk 48454c4f: no handler defined

Test results for
Time: 11.191

OK (10 tests)

Terminal 3: This is what I saw in the middle of logcat dump:

D/ActivityManager(  564): Uninstalling process com.InstrTest

D/ActivityManager(  564): Force removing process ProcessRecord
{4379dad0 785:tr.nth/10041} (tr.nth/10041)

W/ActivityManager(  564): Crash of app com.InstrTest running
instrumentation ComponentInfo{com.InstrTest/

D/ActivityManager(  564): Uninstalling process com.InstrTest

D/AndroidRuntime(  776): Shutting down VM

1. Is not it possible to run instrumentation in above manner?
2. I tried another TestSuite2 in terminal 2 instead of TestSuite1 ,
this also gave same results.

My aim is to run 2 testsuites parallel, using same apk. Is it
Or I have to use two different apks? Is there any way that this is

Any input would be appreciated.



2. gp_initSearch problem

Hi All

While using browser recently in my phone I found the following error
gp_initSearch not found !!!

Can any body help me by telling why this happens ?

Please help !!!



3. nested testcase

4. Byte stream @ "/sys/class/lightsensor/switch_cmd/" getting deleted on Reboot.

5. Intent filters: how do I know which action to use?

6. Class resolved by unexpected DEX

7. Is there any way to use Luke's multitouch application in the Emulator?