I have an app that needs to maintain persistent references to certain contacts on a device. I used to do this by storing ContactsContract.Contact._ID, but I've recently had issues where the _ID would change and I was no longer able to reference the contact.
I switched to using ContactsContract.Contact.LOOKUP_KEY which I understood would be a unique, constant way to reference a contact. However, I've gotten reports that some contacts on some devices have a LOOKUP_KEY of null.
Am I wrong in my understanding of LOOKUP_KEY?
- Can it be null?
- Can it change?
- If yes to either 1 or 2, is there a guaranteed way to store a reference to a contact?
In Contacts DB we have many tables where we save information related to a Contacts, such as
Contacts,Data,Mimetype,RawContacts,Accountsetc.The
ContactsContract.Contact._IDchanges when there is an update , merge or sync to the server , theContactsContract.Contact._IDwill change from time, you need to make use ofContactsContract.RawContacts._IDwhich will be unique and will not change until and unless there is deletion of contact.ContactsContract.Contact.LOOKUP_KEY wiill not be changed until you join a contact with another or you separate a merged contacts. Or you can use coloumn "name_raw_contact_id" from Contacts table which will be same always and not change.