My weather app collects the JSON weather feed from the www every 60 minutes. It also used to collect a seperate XML for Sunrise and Sunset, but a few weeks ago I found the Astro library for B4A so I no longer collect the XML feed, but I still fetch the JSON weather feed every 60 minutes on the hour exactly.
As I've mentioned previously, my widgets are not listed in the standard Android battery usage list so I'm happy about that. I also have an auto IP address updater service that contacts an online server and tells it what my current IP address is, at the moment that is set to every 30 minutes (it used to be every 60 minutes), that service is also not on my battery usage list.
My solution is a mix between your two options, I use a sticky service with StartServiceAt during sleep set to True and that's all. My widgets and services just runs and runs and runs. I also always check for an actual internet connection before executing any HTTP calls to the internet, I test for the internet by using MLWiFi. If MLWiFi says that there's no internet I try again 7 seconds later
I'm sure
@Erel or somebody else will say that my solution is the incorrect way to go but I've not came across any issues with my widgets or services not starting every 60 seconds or 60 to 90 minutes. So in my case if it ain't broke, don't fix it
I've not tried my service set to every 12, 18 or 24 hours, but it does work set to every 6 hours on all my devices. I have almost 3k using my IP address app, nobody has complained about it not updating the online server. The service provider recommends that users of my app set it to update their servers every 15 minutes, mine is set to 30 minutes, it was set to every 60 minutes at one stage with no issues whatsoever.
I personally refuse to use PhoneWakeState in any of my applications
@lemonisdead. I absolutely hate waking up in the morning and checking my battery usage in setting and seeing that my simple widgets or services have taken up 5% of my battery in just 6 hours
, PhoneWakeState is not for me, even when using it like a switch flicking PWS On and Off.
I personally do not use timers for constantly long running tasks...