Content Resolver

Use a Content Resolver to handle the SQL commands (query(), insert(), update() or delete()) to a Content Provider’s data source. Since this can be a demanding task it should not be run on the main thread (e.g. AsyncTask):

Content URI (e.g. content://com.example.android.exampleapp/data) is comprised of: Content Provider Prefix: content:// Content Authority: com.example.android.exampleapp Path to Specific Data: data Against each argument is the SQL equivalent. For query():

ContentResolver resolver = getContentResolver();
Cursor cursor = resolver.query // returns a Cursor object which contains all of the information requested. query() can be replaced with insert/update/delete()
    (ExampleAppContract.CONTENT_URI, // FROM table_name. Developer for Content Provider should have specified this constant in their app
     null, // Projection - col,col,col,... The columns to return for each row
     null, // selection - WHERE col = value. specifies the criteria for selecting rows.
     null, // selectionArgs - No exact equivalent. Selection arguments replace ? placeholders in the selection clause.
     null); // sortOrder - ORDER BY col,col,...

For insert():

ContentResolver resolver = getContentResolver();
Cursor cursor = resolver.insert
    (ExampleAppContract.CONTENT_URI, // FROM table_name. Developer for Content Provider should have specified this constant in their app
     null); // ContentValues - the values to be inserted in array of key-value pairings (key is column name)

For update():

ContentResolver resolver = getContentResolver();
Cursor cursor = resolver.update
    (ExampleAppContract.CONTENT_URI, // FROM table_name. Developer for Content Provider should have specified this constant in their app
     null, // ContentValues - the values to be updated in array of key-value pairings (key is column name)
     null, // selection - WHERE filter specifies the criteria for selecting rows.
     null); // selectionArgs - No exact equivalent. Selection arguments replace ? placeholders in the selection clause.

For delete():

ContentResolver resolver = getContentResolver();
Cursor cursor = resolver.delete
    (ExampleAppContract.CONTENT_URI, // FROM table_name. Developer for Content Provider should have specified this constant in their app
     null, // selection - WHERE filter specifies the criteria for selecting rows.
     null); // selectionArgs - No exact equivalent. Selection arguments replace ? placeholders in the selection clause.

ud851-Exercises-student\Lesson08-Quiz-Example\T08.02