JobScheduler is an API for scheduling various types of jobs against the framework that will be executed in your application's own process. Now, with this example, I will create a simple subclass of JobService and execute an AsyncTask by scheduling with my own period time.
When creating project, please select min API is 21:
Create a simple subclass of JobService, in this, declaring execute an AsyncTask onStartJob() method:
In our activity, there are 2 buttons, one to start JobService scheduling, running jobs after every period time and another to cancel all jobs.
Okey, open MainActivity and put this code:
JobService is alsao a subclass of Service, so you must declaring it in AndroidManifest.xml:
Our output will be like this:
(Sorry for having ads)