Thoughts About Content Providers

by Itamar Rogel » Wed, 30 Apr 2008 00:10:19 GMT


Sponsored Links
 i everyone,
Having developed for Android, I have some thoughts about the content
providers API which I think might be worth sharing; I believe there is
room for some improvements to be made to the content providers API
before it is stabilized and would be interested to hear if there are
other developers who feel the same way.

What's wrong about content providers, you ask? Well, as the API docs
put it, content providers are meant to "encapsulate data and provide
it to applications through the single ContentResolver interface. A
content provider is only required if you need to share data between
multiple applications". So, content providers are meant to allow data
sharing between applications, and as such they must perform some
encapsulation over the data. The question is - to what degree are the
content providers meant to abstract over the data representation &
storage mechanism?
This is important because it deeply affects the way the content
providers API is designed, and thus on anyone writing or using content
providers. And it doesn't seem to me that the API, as it's currently
designed, makes a clear choice on this issue.

On one hand, while most of the content providers rely on an SQLite DB
for their data storage, the API does seem to be designed in an attempt
to abstract over the SQL database. This has various implications, such
as:
1. Not allowing natural usage of join queries, even in cases where it
might make sense. The process performing the query is at the mercy of
the implementor of the content provider - did she choose to allow for
a specific join case or not? And of course, the implementor can only
support joins in an ad-hoc way, e.g. by supplying content addresses
which represent specific cases of joins, or by detecting columns which
belong in different tables in the 'projection' argument and adding the
respective table and adjusting the SQL query correspondingly.
Naturally, not every reasonable usage can be accommodated for this
way. (Personally, I've bumped into such limitations when trying to
perform some non-trivial queries on Android's built-in contacts
database).
2. Compiled SQL statements can't be used, reducing efficiency for
repeating queries.
3. Some useful SQL constructs (e.g. SELECT DISTINCT) aren't
accessible.
4. Only string placeholders are allowed.
Direct access to the SQLite database would naturally make all these
limitations void (IPC issues aside, for a moment). In general, putting
the content provider in the accessing process' way to the data hurts
both sides: The accessing process loses flexibility and efficiency and
the content provider needs to perform various manipulations and
parsing actions in order to generate a proper SQL query to hand the
DB. And because the columns and table names are, by convention,
visible as constants, there is actually not much abstraction going on
in most cases. Of course, we do gain inherent data sharing & lookup
(courtesy of the ContentResolver), and we do want a content provider
to validate all modifying operations, but the current API is simply a
bit limiting.

On the other hand, there seems to be an implicit assumption that all
data sources are indeed backed by an SQL database (specifically, by
SQLite). E.g., say we're implementing a non-SQLite-backed content
provider. What shall we do with the 'selection' parameter of the
query() method, which is effectively a WHERE clause? As far as I can



Thoughts About Content Providers

by Chris Harris » Mon, 05 May 2008 21:55:26 GMT


  think you've hit the nail on the head Itamar.

Why shouldn't I be able to perform arbitrary SQL join queries across
arbitrary tables in arbitrary (sqlite-based) content providers? And
why should a SQL-like API exist for non sqlite-based content
providers?

Perhaps the content resolver could be enhanced to map content urls/
mime types to different content provider interfaces?

Regards,
Chris Harris


Itamar Rogel wrote:
--~--~---------~--~----~------------~-------~--~----~


Sponsored Links


Thoughts About Content Providers

by Itamar Rogel » Wed, 07 May 2008 08:49:34 GMT


 hanks, Chris :-)

The mapping between mime-types and/or content URLs to content provider
interfaces sounds indeed like a very good idea.

I sure hope these issues will get their due attention before any API-
stable of Android is made...

Regards,

Itamar Rogel, Briox
http://www.briox.com

On May 5, 11:55 pm, Chris Harris <[EMAIL PROTECTED]> wrote:
--~--~---------~--~----~------------~-------~--~----~



Other Threads

1. converting ycbcr 420 to rgb

Hi,
I want to display the preview frames of an android smartphone on an
opengl texture. As opengl es only support RGB and the preview frame is
encoded with YCbCr 4:2:0. Therefor I have to convert from one to the
other. Though I wasn't successful in doing so, so far. Maybe someone
can help me with it. I found some sources/example code here:

http://groups.google.de/group/android-developers/browse_thread/thread/c85e829ab209ceea/adca218ec3555c81?lnk=gst&q=ycbcr+420+rgb#adca218ec3555c81
http://www.netmite.com/android/mydroid/donut/development/tools/yuv420sp2rgb/yuv420sp2rgb.c
http://blog.tomgibara.com/post/132956174/yuv420-to-rgb565-conversion-in-android

my code can be found here:
http://code.google.com/p/andar/source/browse/#svn/trunk/AndOpenGLCam/src/edu/dhbw/andopenglcam
especially the classes CameraPreviewHandler.java and
OpenGLCamRenderer.java are important.

When using the example from the android project(http://tinyurl.com/
y9l36tl) it results in this:
http://picfront.de/d/Saj1pYfo4/IMG_7715.jpg

I can get the best result from using the outcommented formula from
(http://tinyurl.com/y9l36tl) and inverting RGB in BGR:
http://picfront.de/d/x4iMqes9/IMG_7717.jpg
it shows red planes in green and some blue edges around everything...

any help is appreciated :D

2. Getting a TextView to span the length of the screen

I've a textview I want to span almost the length of the screen, then 2
buttons at the bottom.

Right now I'm using a relative layout with a textview and two buttons
and I can almost get it the way I want but the only thing is the
textview isn't as long as I want it.  I want it to be as long as
necessary for whatever handset is using it.  So a constant pixel
amount is out.

Lets see if this will work.


-------------------------------------
|                                             |
|                                             |
|                                             |
|                                             |
|                                             |
|                                             |
|                                             |
|                                             |
|                                             |
|                                             |
|----------------     ----------------|
||                  |     |                   ||
|----------------     ----------------|
-------------------------------------

3. Customised grid

4. Need help for a proper way of using Listview paired with a background process

5. if second application installed on phone then first will not found

6. installing multiple apks

7. How to draw a border like each row in a list view