Google-api-java-client for Google Calendar on Android Endless loop

I struggled with a sample android application provided by Google to integrate some of the Google calendar features found here in Google code.

I changed the original code a little bit. Specifically, in the CalendarAndroidSample.java class on line 326, I changed:

CalendarUrl url = CalendarUrl.forAllCalendarsFeed(); 

to calculate:

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

This fills the list with all the events on my calendar.

An infinite loop occurs whenever I add an event to my Google calendar. After adding a new event, the sample application freezes, and looking at DDMS, I see logcat splashing it repeatedly without end:

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

The only way I found to stop the application from looping is to remove the calendar event. As soon as the calendar event is deleted, the application comes back to life and lists my events, BUT, the list now contains all my events repeating again and again. He never stops like a feed.

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

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

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

EDIT:

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

0
source share
1 answer

I was about to delete this post after realizing my sheer stupidity, but I am going to leave it for others who fall just like me.

An endless loop was created because nextLink never became null when there were more than 25 events on my calendar. I assume that without setting the maxResults value, the default value is 25. Therefore, when I had more than 25 events on my calendar, "null" nextLink would never exist, because the returned Atom is exactly 25 events.

If I set maxResults to 50 and only 49 events exist on my calendar, the 50th next Link will be zero, thereby causing a loop to break.

I just installed maxResults on a huge amount, like 1,000,000, for example. I believe that each person has 10 events on his calendar every day and lives up to 80 years, which will be approximately 291,000 events. I figure 1,000,000 is a safe number.

0
source

All Articles