khigianguyen
khigianguyen

Reputation: 139

How many content provider we can implement in one app?

I've read Android dev guide and notice that we can implement different classes for the content provider. So,

  1. There are many content providers or just one content provider in one Android app?
  2. How to properly implement different content provider classes like that?

Here is what I read from the dev guide:

You implement a provider as one or more classes in an Android application

http://developer.android.com/guide/topics/providers/content-provider-creating.html

Upvotes: 4

Views: 6623

Answers (4)

user1923551
user1923551

Reputation: 4712

There is no rule as such that you have to implement only one content provider per application. If your project demands, then you can do so.

If you want to implement multiple content providers in your application package, then make sure that authorities part of each content provider is unique, to route the incoming data requests to each content providers properly.

But having too many content providers can really confuse you and not required. The only scenario that I see to have multiple content providers is, if you are having multiple databases in your application and you want to share all those databases with outside applications. Where you can use separate content provider for each database to share it with outside world.

Hope it helps.

Upvotes: 1

Adrian Monk
Adrian Monk

Reputation: 1051

You can implement as many as you want, as you can see from the documentation here. To register a content provider, you need to add its corresponding <provider> tag in the Android Manifest.

In most cases, however, you won't need multiple content providers. One is usually enough, as it can handle multiple tables. You should only really need more than one if you want your app to provide public access to 2+ separate data entities.

Upvotes: 6

se_bastiaan
se_bastiaan

Reputation: 1704

  1. You can create as many content providers as you want. But do you need them al?
  2. What content provider classes do you want to implement? If you read the page very good you should have seen that it contains links to two pages:
    1. http://developer.android.com/guide/topics/providers/content-provider-basics.html - Content Provider Basics
    2. http://developer.android.com/guide/topics/providers/content-provider-creating.html#ContentProvider - Implementing the ContentProvider Class

I suggest you first read those pages. Google is giving some more information about Content Providers, tutorials and examples:

Upvotes: 1

Stefan
Stefan

Reputation: 4705

You can use (provide as well as use) as many content providers per app as you need. They need different content URIs, of course.

In addition to the uses outlined in the document (your link) you can use content providers for other purposes as accessing data storage. The content URI can have parameters, so you can use a content provider similarly to a web service.

Upvotes: 1

Related Questions