问题描述
我有一个处理同步日历和活动的同步适配器。我能够删除正常的活动就好了。但每当我删除重复发生的事件,我的日历中所有活动消失了。
I have a sync adapter that handles syncing calendars and events. I am able to delete normal events just fine. But whenever I delete a recurring event, all the events on my calendar disappear.
有一件事我注意到的是,每当我删除重复发生的事件,在实例
表被清空,这也解释了消失的事件。在活动如预期
表中,与经常性活动的行从表中删除。
One thing I noticed is that whenever I deleted a recurring event, the Instances
table is emptied, which explains the events disappearing. The Events
table is as expected, with the recurring event row deleted from the table.
是什么原因造成的?
我曾尝试删除在以下几个方面:
I have tried deleting in the following ways:
resolver.delete(
ContentUris.withAppendedId(Events.CONTENT_URI, id),
null,
null
);
resolver.delete(
Events.CONTENT_URI,
Events._ID + " = ?",
new String[]{id}
);
,也可以作为 SyncAdapter
:
resolver.delete(
Events.CONTENT_URI.buildUpon()
.appendQueryParameter(CalendarContract.CALLER_IS_SYNCADAPTER, "true")
.appendQueryParameter(Calendars.ACCOUNT_NAME, account.name)
.appendQueryParameter(Calendars.ACCOUNT_TYPE, account.type)
.build(),
Events._ID + " = ?",
new String[]{id}
);
所有的方法对非经常性项目正常运行,但所有导致实例
删除重复发生的事件时,被清空表。
All methods work correctly on non-recurring events, but all cause the Instances
table to be emptied when deleting a recurring event.
更新
一件事我注意到的是,LogCat中吐出以下错误
One thing I noticed is that the LogCat spits out the following error
- 应用程序:
system_process
- 标签:
BufferQueue
- PID:
1187
- TID:
1518
- Application:
system_process
- Tag:
BufferQueue
- PID:
1187
- TID:
1518
[com.android.calendar / com.android.calendar.AllInOneActivity] BufferQueue:drainQueueLocked:超时等待的消费者
推荐答案
这竟然是我的一部分错误。当我的 SyncAdapter
被添加日历到数据库中,我并没有正确设置字段 SYNC_EVENTS
(http://developer.android.com/reference/android/provider/CalendarContract.CalendarColumns.html#SYNC_EVENTS).具体而言,本场应设置为 1
。
It turned out to be an error on my part. When my SyncAdapter
was adding calendars to the database, I was not properly setting the field SYNC_EVENTS
(http://developer.android.com/reference/android/provider/CalendarContract.CalendarColumns.html#SYNC_EVENTS). Specifically, this field should be set to 1
.
这是很难知道,这是问题,因为我仍然能够在技术上同步(推事件到服务器,并拉离服务器的事件),但我只是运行到我的活动消失的问题。
It was difficult to know that this was the issue because I was still able to technically "sync" (push events to the server and pull events from the server), but I was just running into the issue my events disappearing.
我希望这可以帮助别人了。
I hope this helps someone else too.
这篇关于Android的CalendarContract,删除重复事件导致所有事件消失日历吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!