Browse files

Done T0903- UriMatcher

  • Loading branch information...
GinaHsu committed Oct 17, 2017
1 parent 0074ca1 commit b0de74de897d942bdbd4d9f8d5f0882ac7f0d8bb
@@ -19,6 +19,7 @@
import android.content.ContentProvider;
import android.content.ContentValues;
import android.content.Context;
import android.content.UriMatcher;
import android.database.Cursor;
@@ -29,10 +30,36 @@
// TODO (1) Define final integer constants for the directory of tasks and a single item.
// It's convention to use 100, 200, 300, etc for directories,
// and related ints (101, 102, ..) for items in that directory.
public static final int TASKS = 100;
public static final int TASKS_ID= 101;
// TODO (3) Declare a static variable for the Uri matcher that you construct
private static final UriMatcher sUriMatcher = buildUriMatcher();
// TODO (2) Define a static buildUriMatcher method that associates URI's with their int match
* Initialize a new matcher object without any matches,
* then use .addURI(String authority, String path, int match)
* to add matches
public static UriMatcher buildUriMatcher(){
//Initialize a UriMactcher with no matches by passing in NO_MATCH to the constructor
UriMatcher uriMatcher = new UriMatcher(UriMatcher.NO_MATCH);
All paths add to the UriMatcher have a corresponding int.
For each kind of uri you may want to access, add the corresponding match with addUri.
The two calls below add matches for the task directory and a single item by ID.
uriMatcher.addURI(TaskContract.AUTHORITY, TaskContract.PATH_TASKS, TASKS);
uriMatcher.addURI(TaskContract.AUTHORITY, TaskContract.PATH_TASKS, TASKS_ID);
return uriMatcher;
// Member variable for a TaskDbHelper that's initialized in the onCreate() method
private TaskDbHelper mTaskDbHelper;

0 comments on commit b0de74d

Please sign in to comment.