I’m writing an application that synchronize android contact info with server info. After server info changed I’m updating all raw contacts and everybody happy. But I found out that after updating contact with several raw contacts, contact ID’s value incremented by one. If I update contact from device contact ID will still be the same.
Assume that you have a contact with next data:
contact_id : 42
raw_contact_ids : { 43, 44, 45 }
(1) After update you’ll have:
contact_id : 43
raw_contact_ids : { 43, 44, 45 }
(2) But if you update the same contact uisng your device with user interface you’ll got:
contact_id : 42
raw_contact_ids : { 43, 44, 45 }
I don’t understand such behavior. I assume it may be because contact aggregation but I don’t understand the why results in (2) are not the same as in (1). I’m using next code for updating phone number data in raw contacts:
String selectPhone = Data.RAW_CONTACT_ID + "=? AND " + Data.MIMETYPE + "='" +
Phone.CONTENT_ITEM_TYPE + "'" + " AND " + Phone.TYPE + "=? AND " + Phone._ID + "=?";
String[] selectArgs = new String[] { String.valueOf(rawContactId), String.valueOf(from.getType()), String.valueOf(id) };
ops.add(ContentProviderOperation.newUpdate(Data.CONTENT_URI)
.withSelection(selectPhone, selectArgs)
.withValue(Phone.NUMBER, newNumber)
.build());
Can someone explain me what am I doing wrong? I really need those contacts IDs.
From what I’ve learnt you are better using LOOKUP_KEY when storing or using contacts, using the contact ID doesn’t stay static due to aggregation.