0

My app creates calendar events, where the event's description has a contact name in it. When the user changes the contact name using Phone's Contacts, I would like the change to flow to the calendar event's description field.

What is the best method to do that?

I can think of two options. Both include a copy of the contact names in my own database. When a change occurs, find records changed records and update the calendar event.

The issue is how to efficiently move the new name to my database.

  1. Register a Content Observer on Contacts and compare all contact names.
  2. Use a sync adapter

Which method is really more efficient?

I am not familiar with sync adapters, but I assume that the adapter does not need an account (is there such a thing?), and I would like the change to flow Immediately (i.e. not at the next scheduled sync)

Any help, including a different direction altogether would be much appreciated.

OferR
  • 1,634
  • 19
  • 21

1 Answers1

1

A SyncAdapter absolutely needs an account. The only way to make the system recognize them is to use ContentResovler and some xml resources in your AndroidManifest.xml to associate them with an Account / ContentAuthority mapping.

I suppose you could make up your own do-nothing account, and a serve-nothing authority and have your SyncAdapter not talk to a server... but if so, you would end up with the same thing as a service with a timer call. You can't hijack or work in parallel with an existing SyncAdapter -- There must be one and only one SyncAdapter registered for a given ContentAuthority.

To crossfill data between a pair of ContentProviders, You'd need to implement using a ContentObserver and a service. The downside is that you'll need to work hard to keep your service alive -- it will tend to be killed off during high usage by the OS. Once it's down, you'll need to find a way to start it back up (timer?) and then manually check for changes you missed while your service was dead.

Community
  • 1
  • 1
jcwenger
  • 11,383
  • 1
  • 53
  • 65
  • How would you detect an operation made to the contents? Like insert, update and delete. – setzamora Jul 30 '11 at 06:37
  • Detect an operation where? Inside the SyncAdapter? In that case, the android framwork makes function calls directly when it occurs. If you're talking about the app, it's the ContentObserver that lets you know a specific row or table has new data. In that case, that's worth its own question posted. – jcwenger Jul 30 '11 at 15:35