2

I have a framework that needs to be running in the background even if the app is closed from the Recents view. I implemented this initially as a Service that returns START_STICKY in the onStartCommand method.

I am having doubts over returning START_STICKY in the onStartCommand of the JobIntentService as it seems like it is doing important work for enqueing jobs

Any tips for this?

John Ernest Guadalupe
  • 6,379
  • 11
  • 38
  • 71
  • A `JobIntentService` does not run for very long (~10 minutes maximum). I am not aware that a `JobIntentService` is affected by the user closing tasks from the overview screen, though I have not tried that scenario personally. – CommonsWare Apr 02 '18 at 11:06
  • @CommonsWare but actually the Service I have is crashing in Oreo because it is started from a broadcast receiver. So I thought that's why I need to make it a JobIntentService – John Ernest Guadalupe Apr 03 '18 at 02:35
  • Basically, on Android 8.0+, you cannot have long-running *background* services. If you need it to be long-running, it needs to be a foreground service. Your receiver should be able to call `startForegroundService()` to kick off the service, which then calls `startForeground()`. – CommonsWare Apr 03 '18 at 11:17

0 Answers0