Upgrade to Pro — share decks privately, control downloads, hide ads and more …

JobScheduler API

JobScheduler API

DroidUp 2.0 Tbilisi presentation talk about JobScheduler API

Merab Tato Kutalia

November 19, 2016
Tweet

More Decks by Merab Tato Kutalia

Other Decks in Programming

Transcript

  1. WHAT IS JOBSCHEDULER? • API 21 -> JobScheduler class. •

    can be used to schedule everything that is not time critical for the user
  2. COMPARISON • Conditional scheduling • run only when device is

    on power supply • tasks that require network access or a Wi-Fi connection. • device is idle • start after, deadline, predefined time interval • batch jobs
  3. extend the JobService class, implement the onStartJob and onStopJob. return

    true from on the onStopJob to restart the job. The onStartJob is performed in the main thread, if you start asynchronous processing in this method, return true otherwise false.
  4. STEP 1 • register in AndroidManifest.xml • BIND_JOB_SERVICE allows JobScheduler

    to access our service and only it can do it <service
 android:name=".service.TestJobService"
 android:permission="android.permission.BIND_JOB_SERVICE"
 android:exported="true"/>
  5. CONDITIONS • Network Type (If your job requires network access,

    you must include this condition) • Charging / Idle (do heavy operations while charging) • Minimum Latency / Delay • Periodic • Persistent (needs RECEIVE_BOOT_COMPLETED) • Extras
  6. WHAT ABOUT <21 API??? • AlarmManager (Yes, we love it)

    • Firebase JobDispatcher 
 https://github.com/firebase/firebase-jobdispatcher-android • GCM Network Manager 
 https://developers.google.com/cloud-messaging/network-manager