When I want to check and see if something exists in my ContentProvider
what I usually do is something similar to this
Cursor c = getContentResolver().query(table,projection,selection,selectionArgs,sort);
if(c != null && c.moveToFirst()){
//item exists so update
}else{
//item does not exist so insert
}
but that means I always have to make possibly an unnecessary Database call slowing things down especially the greater number of checks on the database I need to do. There has to be a better way to handle this so I dont always have to query first.
I looked at this question
Android Contentprovider - update within an insert method
but using insertWithOnConflict
only checks the primary key id and in my case that will not work because what I am checking is not the id but a unique string from a server database.
so is there something I can do with the Content Provider so I dont always have to make a query to check if the item exists in it already?