Android 上 Google 日历的 google-api-java-client 无限循环

发布于 2024-11-15 22:24:47 字数 1335 浏览 2 评论 0原文

我一直在努力使用 Google 提供的示例 Android 应用程序来集成一些 Google 日历功能,发现 此处,位于 Google 代码中。

我对原始代码做了一点修改。具体来说,在 CalendarAndroidSample.java 第 326 行的类我已修改:

CalendarUrl url = CalendarUrl.forAllCalendarsFeed();

现在计算:

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

这填充了列表视图与我的日历中的所有事件都很好。

每当我将事件添加到我的谷歌日历时,就会发生无限循环。添加新事件后,示例应用程序就会冻结,查看 DDMS,我可以看到 logcat 不断地重复此内容:

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

我发现阻止应用程序循环的唯一方法是删除日历事件。一旦日历事件被删除,应用程序就会恢复并列出我的事件,但是,列表视图现在包含我的所有事件,一遍又一遍地重复。就像饲料永远不会停止一样。

我最好的猜测是在第 333 行,代码如下:

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

nextLink 永远不会变为 null,从而创建循环。但为什么只有当我添加日历事件时才会发生这种情况?

编辑:

我删除了一些日历事件,它开始工作。好像日历中的事件超过 25 个时,它就会开始循环?这有什么意义?!

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?!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

傲世九天 2024-11-22 22:24:47

在意识到自己的愚蠢之后,我本来打算删除这篇文章,但我会把它留给那些像我一样陷入困境的人。

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

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

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

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文