I have an app that to displays new data in a notification. This data is provided by a network device. I can query this device and compare it the cached data in my service to determine if the notification needs to be updated. My app has a service that has local variables in which it caches the data. If the device has newer data, I present that in a notification to the user. Now I started to get IllegalStateException because Android O doesn't allow startService() gets called when the app is in background mode. I know I can start the service in Foreground mode, but since Android is providing less resource intensive ways, I would like to try something new. Next to the data being cached in local variables it gets stored in Firebase Database.
My requirements:
- Check every 10 seconds (if the screen is on) if there's new data
- Check if there's new data when the screen is switched on
- If there is new data, update the notification
- Needs to be long running and be able to compare new data to old (cached or from firebase) data.
- Can run when the app is in background mode
My thoughts: I've looked at Firebase job-dispatcher (https://github.com/firebase/firebase-jobdispatcher-android#user-content-firebase-jobdispatcher-). Maybe I can configure it to run every time the screen is switched on, and every 10 seconds, to retrieve the new data from the network device and match that up with the data in Firebase database. But maybe it will cost a lot of performance to query the database that often.
Solved this by keeping my service. Android Oreo has forced me to use this service different. Just a short description in case anyone needs it: