Sunday, November 23, 2014

Coursera Content provider Exercise - week 8

This lab will build off of the week 7 Location lab. This application will have the same UI elements and behaviors as the week 7 Lab.

This application, however, manages a user's Place Badges using a ContentProvider.

Because ContentProviders persist data across application sessions, when the application initially starts up, it should get all existing Place Badges from the ContentProvider and display them on the screen.

PlaceViewAdapter extends CursorAdapter - see
- Adapter that exposes data from a Cursor to a ListView widget.
- swapCursor() : Swap in a new Cursor, returning the old Cursor.

This is the most important reason why you have to use swapCursor, it doesn’t close the Cursor when you swap it with another Cursor

- content: scheme indicating data that is managed by content provider
- authority: id for content provider
-path: 0 or more segments indicating type of data accessed
-id : optional is specific record within dataset

Provider: ContentProviderCustom

course.examples.ContentProviders.StringContentProvider.StringsContentProvider class

public synchronized Uri insert(Uri uri, ContentValues value) {

User: ContentProviderCustomUser

DataContract class:
public static final String _ID = "_id";public static final String DATA = "data";public static final String DATA_TABLE = "data_table";
private static final Uri BASE_URI = Uri.parse("content://course.examples.ContentProviders.StringContentProvider/");
// The URI for this table.
public static final Uri CONTENT_URI = Uri.withAppendedPath(BASE_URI,

CustomContactProviderDemo class:
ContentValues values = new ContentValues();
// Insert first record
values.put(DataContract.DATA, "Record1");
Uri firstRecordUri = contentResolver.insert(DataContract.CONTENT_URI, values); 

No comments:

Post a Comment