I’m working on developing an app for Android and need to store contact ID’s in order to keep track of a subset of contacts for use in the app. I’m currently storing the ID’s in a table that’s used locally, but this table becomes inconsistent if a contact is merged with other contacts (the ID used to represent the merged contact often changes). What is the best way to maintain consistency?
My ideas:
-
If there were some sort of intent or system event that is broadcasted then I could listen for that.
-
If the mapping between old ID’s and new ID’s is kept somewhere (ContactsContract.RawContacts?) then I could refresh the field whenever I detect that an ID is no longer valid.
-
Run a background process with a content observer and watch for changes. I’d like to avoid this if possible.
This question seems to tackle a similar problem, but for adding instead of merging contacts: Reacting to new contacts in Android Contacts application.
Any and all ideas welcome!
Store the contact lookup URI (as a string). This URI is created from the
_idalong with the contactlookup_key. These two can build a lookup URI by calling ContactsContract.getLookupUri(). You can lookup the contact by calling ContactsContract.lookupContact() and queryingCONTENT_URIor by queryingCONTENT_LOOKUP_URIwith the lookup URI directly. The Android docs say this about the CONTENT_LOOKUP_URI: