I've written a battery monitor widget that I can update when the screen is turned on using a background Service with BroadcastReceivers and an Alarm. I can also stop updating when the screen is turned off. However, the Service only runs until the system stops the background service.
- I don't want to use a foreground service because the user does not need to be notified.
- Always checking and restarting the background service does not seem like a good solution.
- I don't think I can bind a service to a widget. But, I'm new to this and still learning.
How do I get around this problem? I started looking into WorkManager but haven't found what I'm looking for.
Any suggestions to point me in the right direction would be much appreciated.