Implementing a Delete Method

The delete method in a content provider is responsible for deleting a record based on the where clause that is passed in. The delete method then returns the number of rows deleted in the process.

Like the other methods, delete uses UriMatcher to identify the URI type. If the URI type is a collection type, the where clause is passed through so you can delete as many records as possible. If the where clause is null, all records will be deleted. If the URI type is a single-record type, the book ID is extracted from the URI and specified as an additional where clause. In the end, the code returns the number of records deleted (see Listing 3-30).

Listing 3-30. The deleteO Method Implementation ^Override public int delete(Uri uri, String where, String[] whereArgs) { SOLiteDatabase db = mOpenHelper.getWritableDatabase(); int count;

switch (sUriMatcher.match(uri)) {

0 0

Post a comment