简体   繁体   English

我们可以在一个应用程序中实现多少内容提供商?

[英]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, 所以,

  1. There are many content providers or just one content provider in one Android app? 一个Android应用程序中有许多内容提供商或只有一个内容提供商?
  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 您将提供程序实现为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服务类似的内容提供程序。

  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 http://developer.android.com/guide/topics/providers/content-provider-basics.html - 内容提供商基础知识
    2. http://developer.android.com/guide/topics/providers/content-provider-creating.html#ContentProvider - Implementing the ContentProvider Class http://developer.android.com/guide/topics/providers/content-provider-creating.html#ContentProvider - 实现ContentProvider类

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.

相关问题 如何实现具有多个表的内容提供程序? - How to implement a content provider with more than one table? 我们可以为 WhatsApp 贴纸应用实施多个内容提供者吗? - Can we implement multiple Content Providers to WhatsApp stickers app? 为什么/我们应该在 Android 中使用内容提供程序时实现 BaseColumns? - Why/Should we implement BaseColumns when using a Content Provider in Android? 如何使用Content Provider实现复杂查询? - How to implement complex queries using a Content Provider? 我们如何将aspx页面内容解析到Android应用程序? - How can we parse a aspx page content to an Android app? 如何创建一个内容提供程序,其他应用程序可以读取,但没有人可以写? - how can I create a content provider which every other app can read but none can write? 我们如何将同一提供商的子域添加到基于 TWA 的 android 应用程序? - How can we please add subdomains from same provider to TWA based android app? 从一个应用程序到其他访问的内容提供者 uri - Content provider uris from one app to other access 我如何访问警报内容提供程序 - how can i access alarm content provider 具有列表视图和多对多关系的内容提供商 - Content provider with listview and many-to-many relationships
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM