Android Tutorial

(avery) #1

By : Ketan Bhimani


354 

rowsAffected = sqlDB.update(
TrackPointDatabase.TRACKPOINTS_TABLE,
values, _ID + “=” + id, null);
} else {
rowsAffected = sqlDB.update(
TrackPointDatabase.TRACKPOINTS_TABLE,
values, selection + “ and “ + _ID + “=”



  • id, selectionArgs);
    }
    break;
    default:
    throw new IllegalArgumentException(
    “Unknown or Invalid URI “ + uri);
    }
    getContext().getContentResolver().notifyChange(uri, null);
    return rowsAffected;
    }


In this block of code, a writable SQLiteDatabase instance is
retrieved and the Uri type the user passed in is determined with a
call to the match() method of the UriMatcher. No checking of values
or parameters is performed here. However, to block updates to a
specific Uri, such as a Uri affecting multiple rows or a match on
TRACKPOINT_ID, java.lang.UnsupportedOperationException can be
thrown to indicate this. In this example, though, trust is placed in
the user of this content provider.

After calling the appropriate update() method, the system is
notified of the change to the URI with a call to the notifyChange()
method. This tells any observers of the URI that data has possibly
changed. Finally, the affected number of rows is returned, which is
information conveniently returned from the call to the update()
method.

Implementing the delete() Method

Now it’s time to clean up the database. The following is a sample
implementation of the delete() method. It doesn’t check to see if
Free download pdf