开发者

google-api-java-client for Google Calendar on Android Infinite loop

I have been struggling with the sample android application provided by 开发者_Python百科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?!


I was going to remove this post after realizing my sheer stupidity, but I'm going to leave it up for others who fall hard like me.

The infinite loop was being created because nextLink never became null when I had more than 25 events in my calendar. I'm guessing that without setting a value for maxResults, the default is 25. Hence, when I had more than 25 events in my calendar, a "null" nextLink could never exist because the Atom returned has exactly 25 events.

If I set maxResults to 50 and only 49 events exist in my calendar, the 50th nextLink would be null thus triggering the break from the loop.

I have just set maxResults to a huge number like 1,000,000. I figure if a person has 10 events in their calendar every day and lives to be 80 years old, that would only equate to around 291,000 events. I figure 1,000,000 is a safe number.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜