I am trying to find a way to notify a dependent component when certain rows are deleted, so can I issue a select query, obtain the cursor, then issue the delete or will that modify the original cursor? Is there a better approach altogether? This is what I’m referring to:
Cursor c = builder.query(db, projection, selection, selectionArgs, groupBy, having, sortOrder);
db.delete(table, selection, selectionArgs);
while (cursor != null && cursor.moveToNext()) {
final String name = cursor.getString(0);
// send notifications
}
c.close();
If you use a content provider to access your database then you can use ContentObservers which are designed exactly for this purpose:
When you retrieve data through a content provider you do so with a URI and it is this URI that you can use to notify ContentObserver’s that the cursor has changed:
See the javadocs for
notifyChange(...)for more info:I am afraid to say that you would have to write your own solution for this if you do not use content providers to access your data.