Android Sqlite Transaction and Content Provider
I solved this issue with this code:
if (!valuesToDelete.isEmpty()) { StringBuilder sb = new StringBuilder(); String value = null; for (ContentValues cv : valuesToDelete) { value = cv.getAsString(kei_id); if (sb.length() > 0) { sb.append(", "); } sb.append(value); } String args = sb.toString(); String selection = kei_id + " IN(" + args + ")"; int total = mContext.getContentResolver().delete(uri, selection, null); LOGD(TAG, "Total = " + total); } else { LOGD(TAG, "No data to Delete"); }
Thanks
User ContentResolver object to delete multiple rows.
// get the ContentResolver from a context// if not from any activity, then you can use application's context to get the ContentResolver// 'where' is the condition e.g., "field1 = ?" // whereArgs is the values in string e.g., new String[] { field1Value } ContentResolver cr = getContentResolver();cr.delete(ProviderMyDatabase.CONTENT_URI, where, whereArgs);
So any row with (field1 = field1Value) will be deleted.
If you want to delete all the rows then
cr.delete(ProviderMyDatabase.CONTENT_URI, "1 = 1", null);