类结构具有多个子表ContentProvider的 [英] Class structure for a ContentProvider having multiple sub tables
问题描述
该ContentProvider的医生说,使你的ContentProvider类的AndroidManifest一个条目。如果你的类支持多个子表,那么就必须为每宣布一件CONTENT_URI不变。怎么样?不能对每个子表做,除非你子类。为什么不只是有多个供应商?
你实现分表提供者的后裔?随着多个子表,但仍然只有一个ContentProvider类?
正如你所看到的,我的文档混淆。其内容如下:
定义一个公共静态最终乌里命名 CONTENT_URI。这是字符串 再presents全文:URI的 内容提供商处理。您 必须定义这个唯一的字符串 值。最好的解决方法是使用 的完全限定类名 内容提供商(小写)。所以, 例如,该URI为 TransportationProvider类可能是 定义如下:
公共静态最终乌里CONTENT_URI =
Uri.parse(内容://com.example.$c$clab.transporationprovider);
如果供应商有子表,也可以定义CONTENT_URI常量为每个子表。这些URI应该都具有相同的机构(自标识内容提供商),以及仅由它们的路径区分。例如:
内容://com.example.$c$clab.transporationprovider/train
内容://com.example.$c$clab.transporationprovider/air/domestic
内容://com.example.$c$clab.transporationprovider/air/international
那么,有多少班做我们创建办理列车,空气/国内空运/国际?
如果你的类支持多个 子表则必须有一个 CONTENT_URI不断宣布参加 每。怎么样?你不能这样做,除非 你的子类,用于每个子表
不要他们的名字全部 CONTENT_URI
,然后。这个名字是对第三方多大用处,反正,因为他们将无法访问您的源$ C $ C访问静态数据成员。文档弄得我也一样,我甚至有点人云亦云他们的指示在我的一本书,但我从逐渐远离,将被改造我的材料相匹配。
一个更好的地方,看看是他们自己的内容提供者( ContactsContract
, CallLog
等)。
你实现分表 提供者的后裔?随着 多个子表,仍有 只有一个ContentProvider类?
有你想要的。你可以用一个单独的类做到这一点,或者内部类(见 ContactsContract
),或者什么的。
The ContentProvider doc says to make ONE entry in the AndroidManifest for your ContentProvider class. If your class supports multiple sub-tables then there must be one CONTENT_URI constant declared for each. How? You can't do that unless you sub-class for each sub-table. Why not just have multiple providers?
Do you implement the sub-table providers as descendants? With multiple sub-tables, there is still only ONE ContentProvider class?
As you can see, I'm confused by the documentation. It reads:
Define a public static final Uri named CONTENT_URI. This is the string that represents the full content: URI that your content provider handles. You must define a unique string for this value. The best solution is to use the fully-qualified class name of the content provider (made lowercase). So, for example, the URI for a TransportationProvider class could be defined as follows:
public static final Uri CONTENT_URI =
Uri.parse("content://com.example.codelab.transporationprovider");
If the provider has subtables, also define CONTENT_URI constants for each of the subtables. These URIs should all have the same authority (since that identifies the content provider), and be distinguished only by their paths. For example:
content://com.example.codelab.transporationprovider/train
content://com.example.codelab.transporationprovider/air/domestic
content://com.example.codelab.transporationprovider/air/international
So, how many classes do we create to handle train, air/domestic and air/international?
If your class supports multiple sub-tables then there must be one CONTENT_URI constant declared for each. How? You can't do that unless you sub-class for each sub-table.
Don't name them all CONTENT_URI
, then. That name isn't terribly useful for third parties, anyway, since they won't have access to your source code to access that static data member. The documentation confused me too, and I even kinda parrot their instructions in my one book, but I am moving away from that and will be revamping my materials to match.
A better place to look is their own content providers (ContactsContract
, CallLog
, etc.).
Do you implement the sub-table providers as descendants? With multiple sub-tables, there is still only ONE ContentProvider class?
Have as many as you want. You can do it with a single class, or with inner classes (see ContactsContract
), or whatever.
这篇关于类结构具有多个子表ContentProvider的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!