I have written a Custom Content Provider on top of a SQLite Database. The Content Provider extends SQLiteContentProvider. The content provider send notifications at the end of many insert, delete or update operations. Now I wish to do a few update, insert and delete operation on Database but does not want any notification to be generated. How to achieve this?
Code sample from SQLiteContentProvider#bulkInsert
@Override
public int bulkInsert(Uri uri, ContentValues[] values) {
int numValues = values.length;
mDb = mOpenHelper.getWritableDatabase();
mDb.beginTransactionWithListener(this);
try {
for (int i = 0; i < numValues; i++) {
Uri result = insertInTransaction(uri, values[i]);
if (result != null) {
mNotifyChange = true;
}
mDb.yieldIfContendedSafely();
}
mDb.setTransactionSuccessful();
} finally {
mDb.endTransaction();
}
onEndTransaction();
return numValues;
}
I suggest using a different URI when calling update/insert/delete that you don’t want notifications for
so you’ll have
YourMetadata.CONTENT_URIandYourMetadata.CONTENT_URI_DONT_NOTIFYThen you can perform your inserts/updates/deletes as normal.. just before you notify check to see if your uri is one that you shouldn’t notify on
If you have a URI matcher you can use the code from the match result to determine which URI you did a bulk insert on
If not you can use
then use the value of notifyChanges after you insert to determine if you want to notify or not.