1

I've an app where I link internal data to phone contacts via the ID. The problem is that I can't use default backup and restore mechanisms because after a phone change the contact IDs may change (and often do).

Currently I offer an export and import function that checks names and numbers of contacts and uses this data to update the IDs in the imported data. This is cumbersome and I would like to use androids default backup and restore mechanism but I can't currently as long as my app links internal data to contacts via ID.

How can this problem be handled? Any ideas?

User experience is suffering by the manual export/import a little bit and users do not understand my choice without an explanation.

prom85
  • 16,896
  • 17
  • 122
  • 242

1 Answers1

0

You have 2 options:

Option #1:

Add your app specific data to the contacts. Backup and restore will be handled by android framework. Ref: Contacts provider

The upside is you don't to setup a server to sync the data. The downside is that some other apps might override your data. Also, if a user doesn't take care to login and sync their contacts, you loose your data (and they loose their contacts). Happens more often than you'd think.

Option #2:

Store your data on your server (which I think you're doing anyway). Pick a unique identifier of a user (phone, email)- whatever you use to verify your user. Map your data to this identifier (not the android framework's contact's ID). Setup a syncing process (sync at 4am and/or while charging) and perform the sync.

The upside is you will never loose your users' data. This is what WhatsApp does with chats. Actually, they upload to google drive and do use their server storage for this.

Vedant Agarwala
  • 18,146
  • 4
  • 66
  • 89
  • The problem with the second option is, what do you do if the user renames a contact, adds/changes email or phone numbers and similar? You loose the link to your internal data in this case... WhatsApp is a little easier, the chat belongs to a phone number, this will never change, no matter what... – prom85 Jun 19 '18 at 07:16
  • Well you have to tie it to something **unique**. You said you are already using "names and numbers". Using the second option with it will solve your manual import/export problem. Otherwise you always have option 1 – Vedant Agarwala Jun 19 '18 at 07:26
  • Think about following: I sync data to server, user resets device or changes device, user restores contacts, user renames one contact, my data is synced to device => the link to the renamed contact is lost; same can be played through with user changes the number/email or whatever I use as identifier in the meantime... There simply does not exist a *unique* id that is constant over device changes and user changes... – prom85 Jun 19 '18 at 07:30
  • Then use option 1 and create your own unique ID. Its quite complex to do so, however. – Vedant Agarwala Jun 19 '18 at 07:36