Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Oreo service restriction affect intentservices from job schedulers?

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?

like image 376
Le2e410 Avatar asked Dec 03 '25 07:12

Le2e410


1 Answers

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.

like image 80
ctate Avatar answered Dec 04 '25 22:12

ctate



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!