问题
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?
回答1:
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.
来源:https://stackoverflow.com/questions/2277202/class-structure-for-a-contentprovider-having-multiple-sub-tables