Android app’s have wide range of features to give the user a rich and easy to use UI providing all the android in built services to the users.Also for the developers extending their new features put forth in every new release of their software development kit’s Android SDK’s.

 

Android app’s will work in background (android background service) state to listen to broadcast messages, push services and many other features which extends the app functionality.Like wise there comes up with a┬ájob scheduling software i.e., API called Job Schedulers.

 

Android jobscheduler is a much efficient way of dealing with the things.It will provide a wake lock for the app in default way providing the guarantee that device stays awake until the job is finished. Also it provides a better battery efficiency which is a prime point in any app.

 

 

activity_main.xml

As this tutorial deals with Android JobScheduler UI is a simple one. Just two buttons to start and stop the job scheduler.

 

 

 

MyJobScheduler.java

Add up a android scheduler, a jobscheduler starts from this class where we can find the methods which will start and stop the job.

Let us see the methods

 

This method deals with the job start where also we can initialize our MyJobExecutor.java class so that we can execute our task as the job starts.

 

 

To make it easy to understand i have displayed a small message on the start of the job.Which will get displayed as a Toast message.In onPostExecute method inside onStartJob method as

 

 

And when job is started there should also be a method to stop it

 

 

Full class code

 

Also next come up the MyJobExecutor

 

 

MyJobExecutor.java

Adding a separate thread to run in background.

 

 

 

AndroidManifest.xml

Add two permissions in manifest file

RECEIVE_BOOT_COMPLETED, ACCESS_NETWORK_STATE

 

 

 

Output

 

 

[/et_pb_text][/et_pb_column][/et_pb_row][/et_pb_section]
Show Buttons
Hide Buttons
Read previous post:
Android swipe to refresh view || Pull down refresh

Close