0

I have been struggling with the sample android application provided by Google for integrating some Google calendar functionality found here at Google code.

I've modified the original code just a tad. Specifically, in the CalendarAndroidSample.java class at line 326 I've modified:

CalendarUrl url = CalendarUrl.forAllCalendarsFeed();

to now compute:

CalendarUrl url = CalendarUrl.forEventFeed(settings.getString("accountName", "NULL"), "private", "full");

This fills the listview with all of the events in my calendar just fine.

The infinite loop occurs whenever I add an event to my google calendar. Once a new event is added, the sample app freezes up, and looking at the DDMS I can see the logcat spitting out this repeatedly without an end:

06-19 11:19:28.556: DEBUG/dalvikvm(7493): GC_FOR_MALLOC freed 11761 objects / 519744 bytes in 39ms

The only way that I've found to stop the app from looping is to delete the calendar event. Once the calendar event is deleted, the app comes back to life and lists my events, BUT, the listview now contains all of my events, repeated over and over again. It's like the feed never stops.

My best guess is that at line 333, where the code reads:

String nextLink = feed.getNextLink();
    if (nextLink == null) {
      break;

nextLink never becomes null, thus creating the loop. But why does this happen ONLY when I add a calendar event?

EDIT:

I deleted some calendar events and it started working. It seems as though if the calendar has more than 25 events, it starts to loop? What is the meaning of this?!

4

1 回答 1

0

在意识到我的愚蠢之后,我打算删除这篇文章,但我会把它留给像我一样努力的其他人。

正在创建无限循环,因为当我的日历中有超过 25 个事件时,nextLink 永远不会为空。我猜如果没有为 maxResults 设置值,默认值为 25。因此,当我的日历中有超过25 个事件时,“null”nextLink 永远不会存在,因为返回的 Atom 正好有 25 个事件。

如果我将 maxResults 设置为 50 并且日历中仅存在 49 个事件,则第 50 个 nextLink 将为空,从而触发循环中断。

我刚刚将 maxResults 设置为一个巨大的数字,例如 1,000,000。我想如果一个人每天的日历中有 10 个事件并且活到 80 岁,那将仅相当于大约 291,000 个事件。我认为 1,000,000 是一个安全的数字。

于 2011-06-20T05:58:37.460 回答