Alex Rivera | Logout

What is a Contract Class and how is it used

Asked 2012-02-11T19:29:44.507
29

In the recently updated Android Dev Guide, the documentation for Content Providers contains a section titled Contract Classes. Though there is a link to an example for Contacts, it was not immediately clear what is a Contract Class and how do I create one for my custom Content Provider

Would appreciate some help on this.

Thanks!

Edit
Report

1 Answer

18

A contract class defines constants that help applications work with the content URIs, column names, intent actions, and other features of a content provider. Contract classes are not included automatically with a provider; the provider's developer has to define them and then make them available to other developers.

You can make your own Contract class and define some constants there. For example, column names that you can later call in code that makes queries to the database etc.

Nice example how Contract class is used see this thread Android - How do I load a contact Photo?

answered 2012-02-11T19:33:44.447

Your Answer