JOB SCHEDULER
Element that allow multiple background tasks to be grouped together, in order to minimize battery drain, is based on 3 components
- JobService Service class where task is initiated
- JobInfo Builder pattern to set conditions for task
- JobScheduler Schedule and cancel tasks, launch service
the JobService
class relies on 2 methods that are called on the main thread onStartJob()
and onStopJob()
here an example using async tasks:
There are also parameter that can be set to influence the scheduling of the job:
- minimum latency
- period
- network type
- if task requires the device to be plugged