Android Guaranteed Reference to a Contact

84 views Asked by At

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?

  1. Can it be null?
  2. Can it change?
  3. If yes to either 1 or 2, is there a guaranteed way to store a reference to a contact?
1

There are 1 answers

4
Rahul Patil On BEST ANSWER

In Contacts DB we have many tables where we save information related to a Contacts, such as Contacts , Data , Mimetype , RawContacts , Accounts etc.

The ContactsContract.Contact._ID changes when there is an update , merge or sync to the server , the ContactsContract.Contact._ID will change from time, you need to make use of ContactsContract.RawContacts._ID which 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.