Simple using the JobScheduler API on Android Lollipop

    In this tutorial, you will learn how to use the JobScheduler API available in Android Lollipop. The JobScheduler API allows developers to create jobs that execute in the background when certain conditions are met.
    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:
pic name pic name pic name
(Sorry for having ads)


Previous post
« Prev Post
Next post
Next Post »