IntentService + startForeground vs JobIntentService

前端 未结 2 1944

Since Android Oreo background execution limits, the docs recommend to refactor IntentServices to JobIntentService.

https://developer.androi

2条回答
  •  天涯浪人
    2020-12-30 09:36

    Foreground service is not affected by Doze, but you still have to use wake locks, if you need your task to be continued when the screen is off.

    The JobIntentService (which uses the JobScheduler) manages wake locks for you, but you have less control when the job will be started.

    I would use the foreground IntentService (or Service) for high priority tasks (e.g. downloading a database) that should run immediatelly and that should not be paused / killed by system.

    I would use the JobIntentService in conjunction with AlarmManager to schedule low priority tasks like refreshing the widget's data periodically.

提交回复
热议问题