Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between Android Service and Content Provider

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

like image 407
Lily Avatar asked Aug 19 '10 15:08

Lily


1 Answers

Your understanding of the difference between a Service and ContentProvider is pretty spot on. The key thing is that a ContentProvider simply acts as a conduit for retrieving data, while a Service is meant to do something in the background without user interaction.

like image 132
Erich Douglass Avatar answered Nov 06 '22 17:11

Erich Douglass