Android clock widget not updating have a godly dating relationship

18 May

In this article, I will show you how to add a periodically firing update to your Widget using an ‘Alarm Manager’.I make the assumption that you have already read the introduction Android Widget Coding article, or that you know the basics of App Widget programming.The actual code to update the widget is the same as it was in the previous article, but has been refactored into a method called to avoid repeating ourselves.Have a look at the full code for the class for more information. Using the ‘Alarm Manager’ we can get the Android operating system to send our application an intent on a regular basis.The 5x1 clock widget is the only one currently that passes through the system clock (not using a 1Weather service), and from what we've seen, it should stay up to date.The newer 5x1 clock widget should work correctly, as it's the only widget that we have right now that uses the system clock - which is necessary to keep the app updated on Android 7 (Nougat) and 8 (Oreo).As a result, the Android system limits the frequency of widget updates to once every half hour or greater.That’s no good if you want a frequently updating widget, like a clock.

If they were to use an ‘Alarm Manager’, they could simply wake up their service each time it needed to do an update.What we need here is a method of updating the widget frequently while the screen is on and only when the screen is on.Luckily there is a way this can be done, using a ‘Alarm Manager‘, which is a system service wherein your code registers events to go off at particular times, or at particular periods.Now we’ve told Android that our application is interested in receiving these intents, and we’ve configured the ‘Alarm Manager’ to send the intents out on a regular basis.All that is left is to write the code that will handle the intents when they arrive.