9

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?

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
Roy Solberg
  • 18,133
  • 12
  • 49
  • 76
  • the first link you posted says: `"Bound services are not affected"`, and i believe `RemoteViewsService` is such a service – pskink Jan 10 '18 at 09:46
  • @pskink That's interesting. It does indeed look like a bound service. But, we get a few complaints about the widget not updating and I personally saw the same and got these in my log: `W/ActivityManager: Background start not allowed: service Intent { flg=0x4 cmp=com.example.app.WidgetService (has extras) } to com.example.appWidgetService from pid=-1 uid=10447 pkg=com.example.app` – Roy Solberg Jan 10 '18 at 10:03
  • `com.example.app.WidgetService` and `com.example.appWidgetService` are different, is there some typo? – pskink Jan 10 '18 at 10:06
  • Yes, that's my bad. I searched and replaced the actual package + class name. I always do that on SO. Sorry. :) – Roy Solberg Jan 10 '18 at 10:23
  • Any news? I have the same problem :( – Kram May 06 '18 at 10:53
  • @Kram Unfortunately not. We will probably just stop using RemoteViewsService. – Roy Solberg May 14 '18 at 12:53
  • @RoySolberg ok. In addition I have a problem that the buttons don't react when I click on them. It looks like the AppWidgetProvider was killed. Are you familiar with this? – Kram May 15 '18 at 11:14
  • @Kram No, we haven't seen that. Not even on the Huawei phones that really have messed up the widgets. – Roy Solberg May 15 '18 at 11:59
  • Did you solve this? If you moved away from RemoveViewsService, what direction did you take? – Keith Entzeroth Apr 19 '19 at 22:04
  • @KeithEntzeroth Can't say I really solved it. We had to keep using `RemoteViewsService` to have a dynamic list of items. For Android 8 and 9 we have to use a lot of hacks to have the service running somewhat reliable, but there are so many bugs it's a mess now. Especially https://issuetracker.google.com/issues/63622293 and https://issuetracker.google.com/issues/76112072 are haunting us. – Roy Solberg May 07 '19 at 06:41

0 Answers0