0

Question

How to relink my apps internal data to the new local contacts database, after getting a new phone or after factory resetting the phone?

Informations

My app uses the phones contacts and links all it's internal data to the contacts via the id.

After the user factory resets the phone or gets a new phone, normally the first thing they do is syncing there contacts with google again. The result is a new local contacts database with NEW IDs, so all my internal linkings to this contacts are broken.

Is there a way to restore them? Currently I offer an export/import solution that tries to rematch the contacts based on name + numbers, but I'm interested if there is another way, a better way that always works...

prom85
  • 16,896
  • 17
  • 122
  • 242

1 Answers1

1

There is no way to restore the row ids and you should not rely on them as a reference in your application. The row id is only a unique identifier in the context of this particular contacts database.

You probably want the SOURCE_ID field of a raw contact, which is supposed to depend on the sync source and therefore should be the same after a factory reset or on a different device. But even that's not guaranteed as it's up to the sync adapter to decide that.

Also, you should be aware that some sync adapters might not set/use this field at all, even though it's good practice. Android won't complain if it's not set.

Marten
  • 3,802
  • 1
  • 17
  • 26