Code example for ContentResolver

Methods: queryupdate

0
    public void updateHistoryEntry(ContentResolver cr, String uri, String title,
                                   long date, int visits) {
        int oldVisits = 0;
        Cursor cursor = null;
        try { 
            cursor = cr.query(Browser.BOOKMARKS_URI,
                              new String[] { Browser.BookmarkColumns.VISITS },
                              Browser.BookmarkColumns.URL + " = ?",
                              new String[] { uri },
                              null); 
 
            if (cursor.moveToFirst()) {
                oldVisits = cursor.getInt(0);
            } 
        } finally { 
            if (cursor != null)
                cursor.close();
        } 
 
        ContentValues values = new ContentValues();
        values.put(Browser.BookmarkColumns.DATE, date);
        values.put(Browser.BookmarkColumns.VISITS, oldVisits + visits);
        if (title != null) {
            values.put(Browser.BookmarkColumns.TITLE, title);
        } 
 
        cr.update(Browser.BOOKMARKS_URI,
                  values,
                  Browser.BookmarkColumns.URL + " = ?",
                  new String[] { uri });
    }