I want to delete first “n” rows using content provider.
This is my code:
private void deleteOldItems(int number) {
String where = HistoryTable.COLUMN_ID + "<=?";
getContentResolver()
.delete(Uri.parse("content://com.ipiit.client.contentprovider.HistoryContentProvider/histories"),
where, new String[] {String.valueOf(number)});
}
I works but only one time. How to always delete first rows?
If this is your “own”
ContentProvider, i.e. you are sure of the table names and similar stuff you can always do a rather ugly subselect like this:On the other hand, if it’s your own
ContentProvider.. just add support for adding a “limit” parameter to the URI when passing it to #delete(..) instead of resorting to ugly hacks like this.