plusonelabs / calendar-widget

An calender widget for your Android home screen.
Apache License 2.0
371 stars 126 forks source link

Widget is not refreshing correctly #338

Closed Clubby2010 closed 4 years ago

Clubby2010 commented 4 years ago

I noticed several times that the widget is not refreshing correct automatically.

Example: Screenshot_20191020-224702

As you can see in the screenshot above, the current time is 22:47, but 2 issues:

  1. The event from 15:00-21:00 is not shown in past color
  2. A new added event for the next day is not shown.

After pressing the refresh icon (circle arrow) manually, the calendar is refreshed correctly: Screenshot_20191020-224721

I didn't notice this issue with an older major version of the app.

yvolk commented 4 years ago

The widget is configured to be updated automatically, even when nothing happens, once in several hours. Plus it updates, when several kinds of notifications arrive. The second way is unreliable due to Android design flaw, caused, as I understand, by desire to spend less device energy, see https://github.com/plusonelabs/calendar-widget/issues/298

Decreasing automatic refresh period is generally discouraged. But maybe this is the only way to have automatic refreshes more often...

yvolk commented 4 years ago

@Clubby2010 Regarding comparison with ToDo Agenda v.2. it would be very interesting to have such on the same device and at (almost) the same time. ?!

Clubby2010 commented 4 years ago

@Clubby2010 Regarding comparison with ToDo Agenda v.2. it would be very interesting to have such on the same device and at (almost) the same time. ?!

How can I test this (installing v.2 version in parallel)? I could also test it against other calendar widget if this would be interesting.

yvolk commented 4 years ago

@Clubby2010 I meant sequential testing,of course. It will require uninstalling of one version+ reboot before installing another. BTW v.3.1 has Backup/Restore feature, so you will be able to return to the latest version quickly

Clubby2010 commented 4 years ago

How can I install version v2? By the way I'm using Oneplus3T with OxygenOS 9.0.5 (Android 9). I use aCalendar+ app to manage different google calendars of different accounts :)

yvolk commented 4 years ago

Please download v.2.1.1 from here: https://github.com/plusonelabs/calendar-widget/issues/320

Clubby2010 commented 4 years ago

Tested with 2.1.1 but the error exists there also,maybe I didn't recognized it in the past because of previous Android Version. I have also tested other calendar widgets,which doesn't show this issue.

yvolk commented 4 years ago

@Clubby2010 Thank you for testing. Regarding Android versions, first time I noticed that some scheduled processed aren't working for several hours, was with my Lenovo tablet with Android 7. The tablet does Power saving job very well: one charge in several days. But preventing apps (and widgets) from timely updates is the price for such economy :-( ToDo Agenda tries to use any means to be up to date. E.g. we schedule refresh on every screen unlock. But it appears that this doesn't work on some devices...

There are "brute force" means to ensure constant app running like creation of a "service" always running in a background. But I thought that this would be an overkill for the widget. And will cause noticeable power loss and the ToDo Agenda's icon always present in notification bar.

Or should I create such optional background service for ToDo agenda?

yvolk commented 4 years ago

@Clubby2010 If you find any open calendar widget that updates property on your device, please let me know. I will inspect it :-)

SimenCodes commented 4 years ago

@yvolk Have the same issue, and for me "Your calendar widget" seems to update properly on calendar changes. I suspect this could be related to the implicit broadcast limitations introduced in Oreo? https://developer.android.com/about/versions/oreo/background.html#broadcasts

In another project I'm working on, I've found the Job Scheduler API to work reliably on recent devices:

JobInfo.Builder(…).addTriggerContentUri(JobInfo.TriggerContentUri(
        CalendarContract.Events.
        JobInfo.TriggerContentUri.FLAG_NOTIFY_FOR_DESCENDANTS
))

Edit: Never mind, turns out I was using an old version from f-droid.

yvolk commented 4 years ago

@SimenCodes "Never mind..." So what's your current suggestion for improvement?

Clubby2010 commented 4 years ago

I'm not sure about the Background task.

I'm currently testing the widgets: Your Calendar Widget, DigiCal and aCalendar+. ACalendar+ and YourCalendar are refreshing instantly. But I must say to use aCalendar+ app for calendar editing,here I expect an internal sync between app and widget. But YourCalendar is also fine. DigiCal is also sometimes not refreshing.

SimenCodes commented 4 years ago

@yvolk "Never mind" as in "version 3.0.11-532 from fdroid works for me". My suggestion for improvement if broadcasts are not being received for some people, is still to use the job scheduler.

yvolk commented 4 years ago

@Clubby2010 Today I compared refreshing of "Todo Agenda" vs "Your Calendar Widget" and "Schedule" widget of Google Calendar. "Schedule" widget of Google Calendar shows changes instantly, as expected: it has a privilege to communicate with its parent "Calendar app" in some special way... I see that "Your Calendar Widget" auto refreshes about once in a minute (I don't know always or only in some cases...) and so sometimes it shows changes in events quicker than "ToDo Agenda". But most of the time both widgets show the same poor refresh ability, unfortunately. Even with constant auto refreshes of "Your Calendar Widget" and manual tapping of "Refresh" icon of "ToDo Agenda" I couldn't see changed / deleted or new events in both widget for several minutes... and then suddenly these changes appeared in both widgets at almost the same time.

So "Your Calendar Widget" doesn't use any better technique.

Below screenshot shows that only Google's widget shows "Go2" event, and "Sleep" event in green color. I even lost patience and left my device while waiting for it to appear...

CompareWidgets

Clubby2010 commented 4 years ago

On my smartphone I can't confirm your results. Since a few days I use both widgets, "To do Agenda" and "Your Calendar". I see several missed events in ToDo Agenda but never in Your Calendar. I even see no delay in Your Calendar, after changing (adding, modifying, deleting) an event, the widget is refreshed instantly. If ToDo Agenda wouldn't refresh instant, but only after some minutes, it would be ok for me. But sometimes it's not up-to-date for events more than half day ago, which is not ok for me. Independent from the comparison to other widgets, for me it's one of the core features to have a widget showing up-to-date events, but currently I'm very disappointed. Maybe it's caused by the operating system, my smartphone Oneplus 3T uses OxygenOS based on Android and not pure Android. If I can help further to support on this issue, I will, but otherwise I may switch the app as it's not working as expected for me. I'm sorry.

yvolk commented 4 years ago

@Clubby2010 I understand that "notifications" on calendar events' changes don't work at all on your device. This is why only manual Refresh button tap works.

So it looks like the only substantial difference between the two widgets is in a frequency of automatic and unconditional refreshes, configured for the two widgets. As I noticed, "You Calendar" is configured to auto-refresh at least each minute (or maybe even more often, I didn't decompiled it...) Whereas "ToDo Agenda" was historically configured to refresh automatically once in several hours (because before Android 8 notifications on events changes worked normally). Your observations about several hours confirm this.

I think I will create another widget in the same app called e.g. "ToDo Agenda 1 minute refresh" (if the name isn't too long...) and allow users, who have problems with auto refreshing, add that widget to the screen. This second widget will consume more power energy, but we don't know a better way so far...

?!

Edited: I better use a configurable alarm for this: https://stackoverflow.com/questions/28072947/changing-androidupdateperiodmillis-programmatically https://developer.android.com/training/scheduling/alarms

Clubby2010 commented 4 years ago

@Clubby2010 I understand that "notifications" on calendar events' changes don't work at all on your device. This is why only manual Refresh button tap works.

No, for me the Your Calendar "seems" to be updated by notifications. Of course, I don't know, but it's really instant. I change an event, go back on startscreen, and it's updated. I never see any delay for this widget. You wrote, it's at least auto-refreshed at least each minute. I can't confirm this for my device.

Currently I will compare battery consumptions between both widgets.

yvolk commented 4 years ago

Currently I will compare battery consumptions between both widgets.

As the ToDo Agenda is not updating on your device it should not consume ANY power.

Another thought is that as you are using the "ACalendar+" Calendar app, it may send notifications directly to some "known" widgets. It that case that explicitly notified widgets will really update instantly. Just like recently we agreed with "Open tasks" developer to send us notifications explicitly for quick updates: https://github.com/dmfs/opentasks/issues/822

yvolk commented 4 years ago

@Clubby2010 Regarding one minute refresh in "You Calendar": please look at my screenshot above: "You Calendar" shows "2 min remaining" for one event. And that minutes counter changes every minute! This can be done only by execution of the widget's code during a refresh...

Clubby2010 commented 4 years ago

I asked the developer of Your Calendar widget how it's refreshed,but get no feedback :( Maybe you are right and it's getting notified by a special notification of my calender app. I really think the ToDo widget has a slightly better UI,but as it's only working with manual refresh for me,I will no longer use it. Sorry.

Clubby2010 commented 4 years ago

I just recognize that I closed this issue some days ago. This was accidently. But for me it can be stay closed even If the issue is still there.

yvolk commented 4 years ago

@Clubby2010 @SimenCodes Listening to you :-) I improved automatic widget refresh via introduction of a configurable Auto refresh period (in Other Settings). Default refresh period: 10 minutes. Minimal refresh period: 1 minute, maximum - one day.

The refresh (and corresponding alarm) is not fired, when a device sleeps. So it doesn't spend much energy.

I see that it works. Moreover, testing on Pixel 3 device with Android 10 I see that the Widget is auto refreshed after waking up also (Intent { act=android.intent.action.DREAMING_STOPPED flg=0x40000010 })

Please check v.3.1.7. Beta #320

Clubby2010 commented 4 years ago

Thanks for adding this new setting. I have tested the beta and can clearly see the refresh now.

yvolk commented 4 years ago

Another potential cause of not refreshing/updating found:

You can see outdated data, because ToDo Agenda gets it from "Calendar Provider" Android system service. This is that service that malfunctions (maybe doesn't sync in time...) Delays in data updates for this service are related to your Account synchronization. see Calendar there.

As one of users confirmed:

I found the problem. In the Settings: Accounts area, not all the syncs were turned on. It looks like as of Android 10, you have a sync for Google Calendar and a sync for Calendar. Not sure what the difference is!!!! But turning both on seemed to help.