Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should I use a Content Provider?

I'm reading the official documentation from android's content providers and I've seen this:

Decide if you need a content provider.

You need to build a content provider if you want to provide one or more of the following features:

  • You want to offer complex data or files to other applications.
  • You want to allow users to copy complex data from your app into other apps.
  • You want to provide custom search suggestions using the search framework.
  • You don't need a provider to use an SQLite database if the use is entirely within your own application.

I'm developing an app that syncs data on background when the position changes through an IntentService.

What I've seen is that with ContentProvider you could observe when data changes which I really want without user noticing it. It changes in IntentService and MainActivity observes this changes and when it's notificated, layout content change

Is it a great idea to use a ContentProvider although they don't even mention this?

Thanks

like image 423
Javier Manzano Avatar asked Feb 24 '13 20:02

Javier Manzano


1 Answers

Personally, I have been using ContentProviders in all my projects for the last year and a half. They provide good, database independent, data abstraction to access your data. They are very flexible, I even had a play project where one URI pointed to a SharedPreference while all others where for accessing database tables. ContentProviders also allow you to use already built framework infrastructure such as CursorLoaders, for example. Implementing your own from interfaces and abstract classes is not that hard, but it may be time consuming and error prone, being able to just leverage work that's already been tried and tested is a great advantage.

By the way, I remember the same exact question on a post in google+ about 2 weeks ago where Cyril Mottier gave a very good answer. You can read it here.

like image 61
ebarrenechea Avatar answered Sep 20 '22 01:09

ebarrenechea