2

我有一个同步适配器来处理同步日历和事件。我可以很好地删除正常事件。但是,每当我删除重复事件时,我日历上的所有事件都会消失。

我注意到的一件事是,每当我删除重复事件时,Instances表就会被清空,这解释了事件消失的原因。该Events表如预期的那样,从表中删除了重复事件行。

这是什么原因造成的?

我尝试通过以下方式删除:

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}
);

所有方法都可以在非重复事件上正常工作,但Instances在删除重复事件时都会导致表被清空。

更新

我注意到的一件事是 LogCat 吐出以下错误

  • 应用:system_process
  • 标签:BufferQueue
  • PID:1187
  • 时间:1518

[com.android.calendar/com.android.calendar.AllInOneActivity] BufferQueue:drainQueueLocked: timeout waiting on consumer!

4

1 回答 1

2

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.

于 2013-06-11T07:09:16.650 回答