问题
Android 8 has its background execution limits, so when we started targeting Oreo we changed our services to using JobIntentSerivce to be able to get work done.
However, we have a widget that updates every few minutes with live score data. The widget's service extends the good old RemoteViewsService. How can we make sure that the widget is updated even when the app is in the background?
I've taken a look at the suggestions in another SO question, but they all seem to have some caveats:
JobScheduler
needs aJobIntentSerivce
which I can't see how can be combined withRemoteViewsService
(or can it somehow?)- PendingIntent.getForegroundService() is not perfect when on a poor Internet connection (or maybe a slow device) and will sometimes either give an ANR, and we ideally don't really want to show a notification when we see the time limit is closing in on us
I haven't experimented with BroadcastReceiver.goAsync() yet, but maybe that is my best shot?
来源:https://stackoverflow.com/questions/48184186/how-to-ensure-remoteviewsservice-is-run-in-the-background-in-oreo