3

According to the Google FAQ on instant apps:

For example, an instant app cannot use background services, send background notifications, or access unique device identifiers.

So my main question is: what are the best practices for doing small background work for an instant app? Our installed app currently relies on JobScheduler in our custom analytics client for sending events bulks later when network is also available.

JobScheduler doesn't seem to work for the instant version and we kinda hoped WorkManager would solve the problem. Switching to it seems to work only if there is no initial delay for the job that you want to run so we're kinda out of ideas how to best tackle this issue.

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
Tepes Lucian
  • 908
  • 1
  • 7
  • 17
  • also see https://stackoverflow.com/questions/44656049/android-instantapp-foreground-service – TWL Feb 08 '19 at 17:52
  • also https://github.com/googlesamples/android-instant-apps/tree/master/service – TWL Feb 08 '19 at 18:48
  • @TWL thanks for the links. Foreground service doesn't seem to fit in our use case since the user doesn't rely on the background data to complete. Binding to a service seems like a good idea but I'm hoping for a more simplified solution since we just need to send some data with a delay. – Tepes Lucian Feb 11 '19 at 15:52
  • I remember `JobScheduler` being supported by instant apps. What do you mean by when you say it doesn't work; is there an error in the logs or what? If you have a sample where it works on the installed-app, but doesn't on instant app without any visible log error, then you can send it to https://issuetracker.google.com/components/316045#basic and they'll take a closer look at it (and also provide a link back here from it so others can reference your issue). – TWL Feb 11 '19 at 18:58
  • @TWL this is the error I'm seeing in the logcat : W/ActivityManager: Unable to start service Intent { cmp=com.example.myapplication/.TestJobSchedulerService } U=0: not found D/JobScheduler: Error executing JobStatus{dea843e #u0a353/1 com.example.myapplication/.TestJobSchedulerService u=0 s=10353 TIME=-5s76ms:none READY} – Tepes Lucian Feb 12 '19 at 10:45
  • Submitted an issue regarding this problem : https://issuetracker.google.com/issues/124267857 – Tepes Lucian Feb 12 '19 at 18:01
  • I can confirm that the workaround provided at your google bug works. – TWL Feb 13 '19 at 20:23

1 Answers1

0

For anyone looking into this, we've got an official comment on this issue. Basically JobScheduler is not intended to work for instant apps.

As a workaround, we refactored our background jobs to WorkManager and run them with no initial delay when the app is running as an instant app vs with the intended delay for installed app.

Tepes Lucian
  • 908
  • 1
  • 7
  • 17