To be precise, a ContentProvider is an object that can communicate
with the ContentResolver facade. ContentProvider classes are aware of
the underlying nature of their dataset, while ContentResolver is
agnostic and provides a single interface.

A ContentProvider does not have to wrap a database. It can wrap *any*
source of data. A ContentProvider could wrap a reference librarian on
the telephone (granted, it would be very low bandwidth), although you
might find it much more useful to have the data local to the device.
Note also that ContentProvider is an abstract class, so you probably
want to implement the Big 6 Methods
(onCreate,query,insert,update,delete,getType) if you're making the
actual instance available to external developers. The method
signatures imply to the outside world that your data is organized in
tables of rows and columns. That is, the object mimics a database.
Nothing is implied about what's inside, and the external user
shouldn't have to know. To provide a ContentProvider to external
users, you should provide a "contract class" that defines constants
for the table and column names, the content URIs, and the available
types. Look at the Javadoc for android.provider.ContactsContract for
an example of this.

Another note: If you're only using the ContentProvider in your own
application, and you're using an SQLite database, and you have no
intention of syncing it to anything else, then you might want to skip
making a ContentProvider, and use the SQLite classes directly. I think
that the intent of ContentProvider was to make common, public datasets
available to multiple applications.

The difference between ContentProvider and Service?

ContentProvider establishes a pattern for accessing data that matches
the ContentResolver facade. This makes it easy for an application to
locate the data and access it independently of its internal form.

Service is meant to handle work-intensive tasks in an asynchronous
fashion. Nothing about data is implied. Use a Service to handle
syncing data or keeping something around to use as needed (like an
Alarm object).

Hope this helps. I apologize for hammering on ContentProvider. Just
wanted to point out that you're not limited to databases.

On Aug 20, 4:57 am, Joseph Earl <[email protected]> wrote:
> It sounds like you have the right idea.
>
> A ContentProvider is a wrapper around your database which allows other
> applications to access and modify your database in a controlled
> manner.
> A Service is basically just a long-running task, such as downloading/
> syncing data.
>
> A ContentProvider would provide access to your data to your app and
> others, and you would use a Service to download the new data, which
> would then use your ContentProvider to insert that new data into your
> database.
>
> On Aug 19, 4:49 pm, Lily Zhang <[email protected]> wrote:
>
>
>
> > I am developing an app and get confused about the idea of Service and
> > Content Provider in Android. In practice, what will be the difference
> > between them?
>
> > Content Provider
> > is a facade and it defines a way to share data among applications. You
> > many attach a local database to your app or create Content Provider
> > mapped to a universal database so that all the application on the same
> > device can share it.
>
> > Service
> > is long running processes that need to be decoupled from main
> > activity. It has local and remote service. local service is like the
> > local database, and remote service is like Content Provider sharing
> > the database info.
>
> > What My App is doing?
> > downloads info. from multiple internet resource in the background (I
> > suppose this will be Service) and store the info. into database, and
> > multiple applications will need to retrieve the data, format them and
> > output them to user (I guess it will be a Content Provider).
>
> > What will be the fine line between Service and Content Provider?
> > Newbie in Android, and any suggestion is welcome.
>
> > Lily

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to