i implemented update()from ContentProviderand notified the observer usinggetContext().getContentResolver().notifyChange(uri, null);
My obvious need is that whenever only one line is executed, I want to notify using uri with specific lines, but could not find a way to do this. an additional request, for example "select id where selectionArgs", can do this, but it will be stupid.
onchange(boolean, uri)to get the full uri instead of a specific string, it’s easy to understand that this is because it ContentProvider.update()sends the same thing.
some code for more clarity
update () method MyContentProvider
@Override
public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) {
Log.d("TAG", "update " + uri.getPath());
int count = 0;
switch (uriMatcher.match(uri)) {
case BOOKS:
count = booksDB.update(DATABASE_TABLE, values, selection, selectionArgs);
break;
case BOOK_ID:
count = booksDB.update(DATABASE_TABLE, values,
_ID + " = " + uri.getPathSegments().get(1)
+ (!TextUtils.isEmpty(selection) ? " AND (" + selection + ')' : ""),
selectionArgs);
break;
default:
throw new IllegalArgumentException("Unknown URI " + uri);
}
if (count == 1) {
Cursor c = query(uri, new String[] { _ID }, selection, selectionArgs, null);
long rowId = Long.valueOf(c.getString(c.getColumnIndex(_ID)));
uri = ContentUris.withAppendedId(CONTENT_URI, rowId);
}
getContext().getContentResolver().notifyChange(uri, null);
return count;
}
I am updating the table somehow like
getContentResolver().update(MyContentProvider.CONTENT_URI, values1, MyContentProvider._ID+"<?", new String[]{"3"}));
frankly, the code is hardly related to the question, just trying to give you some context