Reputation: 5597
I know a record can be deleted like this:
getContentResolver().delete(Events.CONTENT_URI, Events._ID + " =? ", eventId);
where eventId is a String array
containing, in this case an event's ID.
In my case, I don't want to delete one event, but multiple. So I've got an array of eventIds containing multiple eventIds.
I could of course loop through the array and delete the events one by one, but is it also possible to delete them using just one call?
Upvotes: 0
Views: 1504
Reputation: 7980
Try this code,
ArrayList<ContentProviderOperation> operationList = new ArrayList<ContentProviderOperation>();
ContentProviderOperation contentProviderOperation;
for (/*loop over your arrayList*/)
{
contentProviderOperation = ContentProviderOperation.newDelete(Events.CONTENT_URI).withSelection(Events._ID + " =? ", new String[]{yourId}).build();
operationList.add(contentProviderOperation);
}
try {
getContentResolver().applyBatch(Contract.AUTHORITY, operationList);
}
// catch the exceptions
More info: ContentProviderOperation
Upvotes: 5