Switch to AlarmManager and foreground service to protect against DOZE and killing of the service
Funny, I started implementing the same app https://github.com/SailReal/nina-foss but sadly haven't found yours. I do not really know Dart but your UI looks much nicer :)
During development I tried a lot different solutions to protect the service to be not killed and against DOZE which both is responsible for the known problem:
the background service is sometimes stopped by the system. To start it again, just open FOSS Warn once.
You need to use an AlarmManager and call the setExactAndAllowWhileIdl method. It will use a bit more battery but I'm using it now for weeks and it consumes not even a percent battery usage while polling once a minute and will be executed during deep sleep as well.
Here you can check the code: https://github.com/SailReal/nina-foss/blob/develop/presentation/src/main/java/de/ninafoss/presentation/NinaFossApp.kt#L104-L115
Also use a foreground service with a ongoing notification displayed, this will prevent the app to get killed. With both together my app is checking for new warning since several weeks without getting killed or just executing the request when not in deep sleep, using setExactAndAllowWhileIdl it is always executed regardless the state of the app.
With version 0.2.9.2 I replaced the workmanager task with an Alarm Manager task. It seems that the background service is now much more reliable. If you want to test, you can find the pre-release here. It would be helpful to have information about reliability as well as battery consumption.
Ideally, one would be able to configure if exact fetch intervals or approximate ones are OK. The former would use AlarmManager, the latter WorkManager.
The fact that the service stops is often a problem with manufactor implementations of AOSP. With aggresive DOZE optimizations apps get killed improperly: https://dontkillmyapp.com
I have had success with PeriodicWorkRequests in my apps on my Pixel phone, which, according to the site, follows AOSP rules.
I'm closing the topic now. If anyone still has problems with background tasks not working, feel free to reopen the issue.