Battery life on Android has been a bit of a sore spot for many users, mostly because it's simply not good enough. Most devices can make it a day on moderate use, and a few can even do so comfortably, very few phones can hit two days without some time on the charger. The Android "L" release is making several improvements to power efficiency via Project Volta, but there are also ways to improve 3rd-party apps, and that's where the new Job Scheduler comes in.

Screen Shot 2014-07-01 at 2.00.16 PM

In the past, if a developer wants to run a background task to pull data from a server or run some processor-intensive work, the app has to listen for certain events or set an alarm to wake up at regular intervals. Once the app is running, it still has to check various environmental conditions to determine whether it's even a good time to do its work or if it should try again later. Not only can this become complicated and error prone, but it's simply wasteful if an app wakes up repeatedly just to keep going back to sleep.

This is the problem JobScheduler is meant to fix. It acts as a dispatcher for apps, responsible for waking them when the right conditions are in effect so there's no need to manually watch for the right situation. Developers simply register a request with a set of criteria, then the Job Scheduler will wake the app when it's ready.

Most apps will use the Job Scheduler to wake them when the device is attached to a charger so they can run the processor for a bit, or when they are within range of wi-fi where they can upload photos or download new content. The scheduler also supports setting a window of time so it can wake up groups of apps. This will often be used by apps that need to perform a task every hour or two, but don't have to run at an exact time. If batches of apps run at the same time, the processor can spend more time sleeping.

If you're a developer and this functionality sounds interesting to you, check out the JobScheduler overview for a brief introduction. There is also a sample project in the preview SDK named JobSchedulerSample that shows how a simple implementation would look. Finally, check out this DevBytes video for a few more details:

The advantages to JobScheduler are pretty great. Not only is it going to help with conserving battery life, but it actually allows for much cleaner code by removing the need to listen for system changes and setting alarms. The JobScheduler class is only available in the Android L Developer Preview, but I'm hopeful that it will turn up in the Android compatibility library, as well.