Implementing Content Providers
We've discussed how to interact with a content provider for data needs but haven't yet discussed how to write a content provider. To write a content provider, you have to extend android.content.ContentProvider
and implement the following key methods:
query
insert
update
delete
getType
You'll also need to set up a number of things before implementing them. We will illustrate all the details of a content-provider implementation by describing the steps you'll need to take:
- Plan your database, URIs, column names, and so on, and create a metadata class that defines constants for all of these metadata elements.
- Extend the abstract class
ContentProvider
. - Implement these methods:
query
,insert
,update
,delete
, and
Get Pro Android 4 now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.