将联系人姓名同步到日历事件描述的最佳方法是什么
我的应用程序创建日历事件,其中事件的描述中有联系人姓名。 当用户使用手机的联系人更改联系人姓名时,我希望更改流到日历事件的描述字段。
最好的方法是什么?
我可以想到两个选择。两者都包含我自己的数据库中联系人姓名的副本。当发生变化时,查找记录发生变化的记录并更新日历事件。
问题是如何有效地将新名称移动到我的数据库中。
- 在联系人上注册内容观察者并比较所有联系人姓名。
- 使用同步适配器
哪种方法确实更有效?
我不熟悉同步适配器,但我假设适配器不需要帐户(有这样的事情吗?),并且我希望更改立即生效(即不在下一次计划同步时)
任何帮助,包括完全不同的方向将不胜感激。
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.
- Register a Content Observer on Contacts and compare all contact names.
- 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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
SyncAdapter 绝对需要一个帐户。 让系统识别它们的唯一方法是使用 ContentResovler 和 AndroidManifest.xml 中的一些 xml 资源将它们与 Account / ContentAuthority 映射关联起来。
我想您可以创建自己的不执行任何操作的帐户和不执行任何操作的权限,并让您的 SyncAdapter 不与服务器通信...但如果是这样,您最终会得到同样的结果作为带有计时器调用的服务。您不能劫持现有的 SyncAdapter 或与现有的 SyncAdapter 并行工作 - 必须为给定的 ContentAuthority 注册一个且只有一个 SyncAdapter。
要在一对 ContentProvider 之间交叉填充数据,您需要使用 ContentObserver 和服务来实现。缺点是您需要努力保持服务处于活动状态 - 它往往会在操作系统的高使用率期间被终止。一旦它停机,您需要找到一种方法来启动它(计时器?),然后手动检查您在服务停止时错过的更改。
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.