With the new background service restrictions introduced in Oreo, I'm having a hard time finding a place to clarify whether IntentServices can still be launched from a JobScheduler while the app is backgrounded.
I have a very important feature based around geofencing that needs to run an intentService after a fence is broken. I spent a long time setting it up to queue up jobs when fences are broken and the app is in DOZE for Nougat. When the job is finally run by the OS when the window of network connection is reopened, I spin off each job one after the other in an intentService. Can I no longer do this now that I'm technically starting a service while the app is not in the foreground or is this still permitted since I'm using the JobScheduler?
You should not assume that your app is able to start services from a job. In particular, apps are frequently still in a background state when their jobs execute, and calling startService()
while in a background state will throw an exception. Of course, it is always legal to call startForegroundService()
; though obviously this has UI implications as well.
JobIntentService
is explicitly intended to replace IntentService in a way that is compatible with Android O+ background restrictions. You should look into switching to that instead of using the legacy IntentService support class.