Kakashi
Kakashi

Reputation: 3549

What is content provider?

I just followed tutorial in developer.android.com to create sync adapter to provider feature "synchronization between local db with server db", and after bloody trial and error i managed to make it work (onPerformSync has called successfully).

And now for next step to create sync feature, from what i have read in several articles, I need to create a content provider. I already read https://developer.android.com/guide/topics/providers/content-provider-basics.html but I still dont get it how does it work.

from this link https://developer.android.com/guide/topics/providers/content-provider-basics.html, it raised several questions in my head:

  1. what table they are talking about? are they talking about sqlite table or some "another" table?

  2. content://user_dictionary/words what uri is this? is this uri to table file where sqlite stored? if it's, how do I know mine? I mean where did my sqlite store table that I created?

  3. from what I read (if i got it right), ContentProvider just like a repository. do they have same functionality? I already created my repository using anko https://gist.github.com/mockiemockiz/a552a669d28a3c90c144bc1542b86a5e , can I use that code / convert that code to be ContentProvider that able to tell sync adapter the data has changed?

Upvotes: 3

Views: 983

Answers (1)

CommonsWare
CommonsWare

Reputation: 1006614

I just followed tutorial in developer.android.com to create sync adapter to provider feature "synchronization between local db with server db", and after bloody trial and error i managed to make it work (onPerformSync has called successfully).

FWIW, SyncAdapter is not especially popular.

what table they are talking about?

The word "table" shows up 40 times on that page. We have no way of knowing which of those 40 concerns you, and they use the term in multiple ways.

what uri is this?

That is a Uri pointing to a collection of data ("table") in the user_dictionary ContentProvider.

is this uri to table file where sqlite stored?

That is for the developer of the ContentProvider to decide. The ContentProvider API does not stipulate where the data is stored. It could be stored in SQLite, or a JSON file, or whatever. Convention says that a collection of data exposed by a ContentProvider maps to a SQLite table or view, but that is not required.

if it's, how do I know mine?

You know it is your ContentProvider if you used user_dictionary as your authority (see android:authorities in the <provider> element in the manifest).

I mean where did my sqlite store table that I created?

That is up to you. ContentProvider has nothing to do with SQLite, unless you write code that ties a ContentProvider implementation to SQLite.

ContentProvider just like a repository

Not really, at least in terms of how I use the term "repository". A ContentProvider is a wrapper around some data storage mechanism, to allow outside parties to have controlled access to that data.

can I use that code / convert that code to be ContentProvider that able to tell sync adapter the data has changed?

That would be rather difficult. This is one of the reasons why few developers use SyncAdapter.

Upvotes: 3

Related Questions