01
Jul
dispatcher

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.

Cody Toombs
Cody is a Software Engineer and Writer with a mildly overwhelming obsession with smartphones and the mobile world. If he’s been pulled away from the computer for any length of time, you might find him talking about cocktails and movies, sometimes resulting in the consumption of both.

  • godutch

    Why don't Google hire Oasis Feng (creator of greenify), his app manages to safe a lot of battery without sacrificing functionality

    • HellG

      Actually it DOES sacrifice functionality,it simply end the apps as if they were ended by users thus stopping the system from running them back up as in the case of all task killers,By forcing the apps to stop instead of giving them an API to control and manage that no app will ever run in the background even if it wants to.

      And no offense to the coder i'm a long time user of the app and contributed to translating it,but the app itself is rather simple (still quite amazing) that google would need to hire him to do that,there's no magic behind it that he needs to explain,he still done wonderful job nonetheless.

    • Just_Some_Nobody

      It sacrifices a LOT of functionality. That's how it works.

      • godutch

        You need the donation version and xposed, I have not missed a notification or any functionality

        • David Vargas

          You're just right. When you enable the donation package and Xposed, GCM will work fine, and all your notifications will come at time.

          I pretty like how it works, and how I save battery without missing any notification or functionality.

  • Phil Oakley

    Can't believe how good Android is going to get with L.

    I don't want to call it 5.0 since it's never been called that officially (I'm pretty sure the Android team are ditching version numbers), but this is equivalent of the 2.3/3.2 ->> 4.0 jump.

    Can't wait for the full event and release.

    • Daniel

      Maybe they're ditching dessert names too.

      • Phil Oakley

        I (and some others) have a theory the next Android version will be called "Lego'. i.e. they're stopping using version numbers and going with product endorsement instead, a la KitKat.

        • letsplaay

          I was always skeptical of that possibility since Lego is also the name of the whole company.

        • littlevince

          They should reserve Lego for Project Ara. :P

          • miri

            They indirectly announced that L is the version that will support modularity for Ara ;)

          • Cerberus_tm

            Ooh did they announce that? Does that mean the first Ara frame + modules will come out this autumn?

        • https://play.google.com/store/apps/developer?id=iWizard Bikram Agarwal

          Yep, I posted that opinion on Reddit and got downvoted to oblivion. Almost everyone argued "it's not a dessert".

          • WORPspeed

            Not yet!

            Google Chocolate Factory announcement imminent!
            First product? A Lego chocolate bar (seriously, the way lego looks I am surprised they haven't made a chocolate bar out of it yet)

            Also HL3 confirmed!

          • claudineabelson

            like Jacqueline implied I'm
            taken by surprise that a mom can earn $8130 in 1 month on the computer . see
            post F­i­s­c­a­l­p­o­s­t­.­C­O­M­

        • http://liveinalux.com/ mankulito

          get a life, who the fuck cares it will by lolipop or lava or lickyourassloser.

          • asd

            unfortunately the bot doesn't bother your opinion

          • Phil Oakley

            Well don't you sound like a nice person.

        • Bluewall

          Hey Phil ! Yeah it's going to be Lego. You heard it here first.

        • Gussy2000

          SPACESHIP!

      • Henry Dorsett Case

        What happened to lime pie?

        • Daniel

          Or lamb pie?

          Maybe they'll get into savory dishes.

    • Patricia Smith

      tіl­&nbspі­&nbspsаw­&nbsptհe­&nbspreсeірt­&nbspwհісհ­&nbspհаd­&nbspsаіd ­&nbsp$7023,­&nbspі­&nbspdіdո't­&nbspbelіeve­&nbsptհаt...my...­&nbspbrօtհer ­&nbspwаs­&nbsptrսly­&nbspbrіոgіոg­&nbspіո­&nbspmօոey­&nbspраrt­&nbsptіme ­&nbspօոlіոe..­&nbsptհere­&nbspbest­&nbspfrіeոd­&nbspհаs­&nbspbeeո­&nbsp dօіոg­&nbsptհіs­&nbspfօr­&nbspօոly­&nbsp11­&nbspmօոtհs­&nbspаոd­&nbspjսst ­&nbspсleаrd­&nbsptհe­&nbspmօrgаge­&nbspօո­&nbsptհere­&nbspmіոі­&nbsp mаոsіօո­&nbspаոd­&nbspрսrсհаsed­&nbspа­&nbspոew­&nbspոіssаո­&nbspGT-R:.­&nbspreаd­&nbspmօre­&nbspаt,...&nbsphttp://Makecashonlinejob&#x32&#48&#x31&#52viewskqlvJkw...

      ★★★ �★★★ ★★★ ★★★ �★★★

    • alexio92

      L in roman numerals is 50----> Android 5.0. Easy!

      • Emma John

        сօle.­&nbsptrսe­&nbsptհаt­&nbspWаyոe`s­&nbsp аrtlсlee­&nbspіs­&nbspոісe...­&nbspօո­&nbspsаtսrdаy ­&nbspі­&nbspgօt­&nbspа­&nbspոew­&nbspGMс ­&nbspfrօm­&nbspmаkіոg­&nbsp$9762­&nbsptհіs ­&nbsplаst­&nbsp4­&nbspweeks­&nbspаոd­&nbsp wօսld­&nbspyօս­&nbspbelіeve,­&nbspteո­&nbspk ­&nbsplаst-mսոtհ.­&nbspіt's­&nbspby-fаr­&nbsptհe­&nbspbest­&nbspwօrk­&nbspі've­&nbsp ever­&nbspհаd.­&nbspі­&nbspstаrted­&nbsptհіs ­&nbsp8-mօոtհs­&nbspаgօ­&nbspаոd­&nbspрretty­&nbspmսсհ ­&nbspstrаіgհt­&nbspаwаy­&nbspstаrted­&nbsptօ ­&nbspbrіոg­&nbspіո­&nbspаt­&nbspleаst­&nbsp$80 ­&nbspрer/հr.­&nbspі­&nbspfօllօw­&nbsptհіs­&nbspgreаt­&nbsplіոk,..&nbsphtt&#x70://CashConvertmark&#x32&#48&#x31&#52sincepwToaI4i...

        ❤❤❤ ❤�❤❤ ❤❤❤ ❤❤❤� ❤❤❤

      • Just_Some_Nobody

        L comes after K, so 4.5. Easy!

        • Alex Styl

          Half life 3 confirmed?

          • shaunajdavidson

            My Uncle
            Joshua just got an almost new white Kia Rio Hatchback only from working
            part-time off a home computer. try this R­e­x­1­0­.­C­O­M­

  • s.s

    Sadly so many great Android features go unknown and unused by developers.

    Google needs to do something about this. Force or at least encourage and reward developers who build great apps with the new APIs on the Play Store.

    • liam

      They could star apps that do the right thing.
      As part of their automated testing framework they could check to see if the app is making use of these APIs.

      • Pierre Gardin

        They could rank these apps higher in the search results.

        • WORPspeed

          that is supposed to be the user's job. Uninstall shitty apps, downvote them and upvote the apps from developers that DO use these things.
          I don't want Google to curate the list too much!
          POWAH TO THA PEEPOL!!

          But seriously, they could add a check to each app that tests whether it uses all the cool things google introduced and present it as a checklist on the app's page in teh Play Store. That way it becomes much more visible to the users who can then decide whether the app is good with(out) those features and rate the app appropriately (ofc no one is going to bother to read the list except us enthousiasts and in a perfect world where everyone read it we wouldn;t need it because developers would do it by themselves)

      • Just_Some_Nobody

        That would be cool. Kinda like an Energy Star rating for apps that are known to be better on battery life.

    • http://www.androidpolice.com/author/cody-toombs/ Cody Toombs

      I think that "forcing" or otherwise extending special treatment would be a bad precedent to set. After all, there was even some blowback over the Play Store giving preferential placement to apps that offered a tablet-optimized interface.

      Since most of these features will not be back-ported to older versions of Android, most developers are justified in avoiding them for a period of time so that the market can catch up. The problem is that 2 years from now, most developers will have completely forgotten that stuff like the JobScheduler were added, and they might never update their apps to take advantage of it. That's one of the biggest advantages for putting something like this in the compatibility libraries, even if it's limited or doesn't work as efficiently.

  • NorCalAngler

    Does AP have any contacts within Google to ask about how Google is going to manage this developer release? Are they going to release future developer releases and, if so, via OTA or via factory images? I'm holding off on using it as a DD until I know how it's going to be updated.

    • Manuel Mas
      • KoRRo

        i think this only refers to the emulator images, delivering device updates through the sdk manager doesn't make sense to me...

      • http://www.androidpolice.com/ Artem Russakovskii

        Pretty sure that's only for the SDK.

    • http://www.androidpolice.com/ Artem Russakovskii

      We were unable to get answers about this. We asked.

    • http://www.androidpolice.com/author/cody-toombs/ Cody Toombs

      You really can't get a much better answer than this (Android Fireside Chat ~44 min): https://www.youtube.com/watch?v=K3meJyiYWFw#t=2649

      P.S. That's actually me asking the question.

  • mgamerz

    So how many years will it take to implement in the Facebook app?

    • Felipe Pimenta

      My guess is around 2 years. More or less the same time they took to kinda make their app Holo

  • Jordan Thoms

    Google needs to come up with a way to encourage apps to move over to this, and while they're at it punish apps that unnecessarily use long running services - as they hinted at in the talk about volta, the major benefits of this will only show up once all the apps are using it. Maybe if they detected usage of the old job schedulers using Bouncer and applied a penalty to the apps placing in the store (while telling the developer why)?

  • pfmiller

    How is the new scheduler different from setInexactRepeating alarms which they've had in Android basically forever? And they've also always had intents you can handle to notify of going on or off battery. Is there anything here that's really new, or is it just repackaging existing capabilities in one place so they are easier to use?

    • http://www.androidpolice.com/author/cody-toombs/ Cody Toombs

      In a sense, yes, this is repackaging those things, but you've ignored all of the important advantages and differences. The old way of doing it required setting multiple alarms and registering multiple BroadcastReceivers, then organizing all of your checks. That's a recipe for spaghetti code.

      Cleaner code is just one advantage. The other benefit is that apps using JobScheduler never have to wake up until all of the right conditions have been met. There's no need to spin up a process each time a trigger goes off. That's a big deal when it's 10+ apps that wake up every time the phone is plugged in, changes networks, or wake up at intervals of approximately 60 minutes. Instead, it's just a single service in the operating system that takes responsibility for checking all of the right stuff. This could be a profound reduction to power consumption, and even remove many of the wakelock issues caused by some 3rd-party apps.

  • RarestName

    How is this different from Background App Refresh?

    • Android Developer

      what's "Background App Refresh" ? isn't it of IOS ?

      • RarestName

        Yes, it's from iOS 7. Just looks similar to me.

        • Android Developer

          Good question, though Android already has plenty of ways to handle background operations.
          How does IOS's method works?
          I'm not familiar enough with both of them.

          • RarestName

            It refreshes applications (that you enabled) in the background at appropriate times. Takes into account your app launching habits, time of the day, Wi-Fi connection, charging status and more IIRC.

            Seems like this one is more powerful though.

          • Android Developer

            What does "refreshing applications" mean?
            Here I think it sends an intent to one of the app's components, which will let it deal with it anyway it wants.
            The API looks to work like this:
            the app says: I want to update something between X and Y hours from now, but only if Z is happening (Z can be "only wifi is connected" for example) , and the framework does whatever it can to perform it together with other apps, so that the device would wake up for more than a single app, together.
            Maybe there are other rules it can offer, but I can't find the documentation of it.

  • Jeremy Smith

    So far it seems to be working as advertised. My nexus 5 is currently sitting at 38% with 4 hours SOT, around 13 hours since full. Granted it's on Wi-Fi, but it includes a 30 minute hangout, and a couple hours streaming music. Not to mention when it's idle it flat lines. I've gotten 4 hours SOT on kitkat, but never had battery left. I can't wait till everything is all optimized. This release is looking mega

    • Android Developer

      but it's a part of the SDK, meaning that apps need to be updated to use these classes and functions.
      I think that what you see is because of other optimizations that Android got, which affect all apps without any need to modify the apps.

  • Just_Some_Nobody

    I wonder if this will reduce the number of wakelocks as well. (Maybe I should read the quoted material before commenting, but I can't help myself)

    • Dan Gerbe

      It most certainly will.

    • http://www.androidpolice.com/author/cody-toombs/ Cody Toombs

      It won't get rid of the need for them, but it will reduce the frequency with which they are created. Since an app is generally woken by either an alarm or a broadcast, it would create a wakelock while it made a decision about performing a task or not. Even if it doesn't do any processing or call out to the Internet, a wakelock usually had to be created just so there would be enough time to make that determination.

      In theory, with the JobScheduler, most apps will only ever wake up when they actually should do a task. At the very least, they shouldn't have to wake up as frequently, and that ultimately reduces the frequency of unnecessary wakelocks. How much that actually affects battery life will depend on a lot of other factors, but it will probably always come out better with the JobScheduler.

  • blindexecutioner

    I'd be happy if they just added a couple MM to the thickness of the current phones and increased the mah by 1000 or so.

  • http://bit.ly/Clixense Jaroslav Hrodek

    Hey, you want to earn? Work for Clixsense and start earning. I have earned over 350 USD ..

    http://bit.ly/Clixense

    http://wad.ojooo.com/register.php?ref=rotekja

  • http://liveinalux.com/ mankulito

    look at me, i have 5 monitors, i am very important

  • Hue

    that dude in the last video has a strong trinidadian accent lol

Quantcast