How to ensure RemoteViewsService is run in the background in Oreo?

放肆的年华 提交于 2019-12-21 10:43:19

问题


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 a JobIntentSerivce which I can't see how can be combined with RemoteViewsService (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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!