IntentService + startForeground vs JobIntentService

前端 未结 2 1945

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

https://developer.androi

相关标签:
2条回答
  • 2020-12-30 09:25

    If you want to make long running operation something like Music Player use Foreground Service with notification. because JobIntentService has time execution limit like JobScheduler. ( 10 minutes)

    If you think that user don't need to know about your work you can use JobIntentService without notification.

    You don't need to worry about Doze mode if user is actively using your app.

    There are some cases for Doze mode, according to https://www.bignerdranch.com/blog/diving-into-doze-mode-for-developers/

    Light-Doze starts to kick in shortly after both the screen is off and the device is not charging, waiting only a couple minutes before applying the restrictions just to make sure the user has stopped using their phone

    For example, user turned screen off while you are computing something. Your task is finished and you want to run background service. In that case your JobIntentService can be deffered, because device can be in doze mode.

    However, if you want immediately perform background operation use ForegrounService with WakeLock, because ForegroundService is not working when the screen is off.

    0 讨论(0)
  • 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.

    0 讨论(0)
提交回复
热议问题