[英]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. 我已阅读Android开发指南,并注意到我们可以为内容提供商实现不同的类。 So,
所以,
Here is what I read from the dev guide: 以下是我从开发指南中读到的内容:
You implement a provider as one or more classes in an Android application
您将提供程序实现为Android应用程序中的一个或多个类
http://developer.android.com/guide/topics/providers/content-provider-creating.html http://developer.android.com/guide/topics/providers/content-provider-creating.html
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. 要注册内容提供商,您需要在Android Manifest中添加相应的
<provider>
标记。
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.
如果您希望应用程序提供对2个以上独立数据实体的公共访问权限,那么您应该只需要多个。
You can use (provide as well as use) as many content providers per app as you need. 您可以根据需要使用(提供和使用)每个应用程序的尽可能多的内容提供商。 They need different content URIs, of course.
当然,它们需要不同的内容URI。
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.
内容URI可以包含参数,因此您可以使用与Web服务类似的内容提供程序。
I suggest you first read those pages. 我建议你先阅读那些页面。 Google is giving some more information about Content Providers, tutorials and examples:
Google正在提供有关内容提供商,教程和示例的更多信息:
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. 希望能帮助到你。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.