Android101 - Content Providers

304 views

Published on

A glance at Content Providers and how to use them.

Published in: Education, Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
304
On SlideShare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
13
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Android101 - Content Providers

  1. 1. Content Providers Please download and open: http://goo.gl/aDmGsR
  2. 2. ContentProvider  Manages data  Can use almost any storage option  SQLite  File  API  …  Provides consistent interface (CRUD)  Can be restricted with permissions extends ContentProvider class
  3. 3. Use Case Objects Storage
  4. 4. Interactions ContentProvider Registers ContentResolverContentResolver CRUD CRUD CRUD Your App Other Apps Platform
  5. 5. CRUD Method Usage insert Inserts one object. The URI must be directory-based query Queries for all objects that fit the URI. update Updates one or all object(s) delete Deletes the object(s) for the URI provided.
  6. 6. Insert (Create) Type Name Usage URI uri The URI of the object(s) to access. ContentValues values The values for the object to add.
  7. 7. Query (Read) Type Name Usage URI uri The URI of the object(s) to access. String[] projection This String array indicates which columns/attributes of the objects you want to access String selection With this argument you can determine which records to return String[] selectionArgs The binding parameters to the previous selection argument String sortOrder If the result should be ordered you must use this argument to determine the sort order
  8. 8. Query (sample)
  9. 9. Update(Update) Type Name Usage URI uri The URI of the object(s) to access. ContentValues values The values for the object to add. String selection With this argument you can determine which records to affect String[] selectionArgs The binding parameters to the previous selection argument
  10. 10. Delete(Delete) Type Name Usage URI uri The URI of the object(s) to access. String selection With this argument you can determine which records to affect String[] selectionArgs The binding parameters to the previous selection argument
  11. 11. Use Case (people)
  12. 12. URI  content://authority/path/id  authority: is Java namespace of the content provider implementation. (fully qualified Java package name)  path: is the virtual directory within the provider that identifies the kind of data being requested.  id: is optional part that specifies the primary key of a record being requested. We can omit this part to request all records.
  13. 13. URI (sample)  authority: our authority is… com.example.rememberme.provider.PersonContentProvider  path: using table name person
  14. 14. UriMatcher  Helper class to match URIs to a specific integer codes. UriMatcher (sample)
  15. 15. MIME Types  Used to determine supported object types  Prefixed with:  vnd.android.cursor.item  Single item  vnd.android.cursor.dir  List of items
  16. 16. MIME Types (sample)
  17. 17. Let’s get coding…

×