Question

As per my understanding, Content Provider is a means for accessing database contents.

And to access the database, the Authority part is required. This authority part is provided by CONTENT_URI. Thus Content_URI is a means for giving authority to the database. As far as CONTENT_URI is concerened, it is generally of the form

content://com.example.transportationprovider/trains/122
______ |____________________________________|_____ |___ 
  A                      B                     C     D
Where A = Content,
      B = Authority Part
      c = Path determining what data to request
      D = specific data

Above scenario is a ideal scenario where-in we pass /trains as the only database name. But what if, i have the following content_uri:

content://com.example.transportationprovider/land/bus/133

In this case, /land/bus is the path segments.

But then internally how this data is stored in the database ? Or how content Provider interpret this data?

Please help me.

Was it helpful?

Solution

The simple answer is that it's stored in the database however you like. Everything in in the path, and the mapping of the path to the database underneath, is defined by the writer of the ContentProvider.

More or less, the model you want to use is that you have one path per table in your database.

There are some cases where you might want some additional paths. Typically, this means exposing some alternate "view" of the database... The Contacts API provides a great example of this.

Why do you want to enforce this kind of hirearchy "land/bus"? Why not just "bus" and "train". with one SQL table each? SQL tables are not Java classes. They don't have inheritance relationships and that sort of hirearchy isn't necessary.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top