failed operation at a future time • On a given retry schedule • Perform non-urgent work when certain preconditions are met • Downloading supplemental data
Handler.postDelayed() • Requires the app to continue running during the interim — Resources • If the app crashes or the user kills it, we lose our task • Not robust • AlarmService • Works well if you can’t use JobScheduler (< 21) • https://github.com/evant/ JobSchedulerCompat • Non-persistent across reboot • Retries must be set up manually • Does not consider device state
android.permission.BIND_JOB_SERVICE in the Manifest • Obtain JOB_SCHEDULER_SERVICE with Context.getSystemService() • Create a JobInfo.Builder, passing in the class of your JobService extension • Set options on the Builder • MinimumLatency, RequiredNetworkType, RequiresDeviceIdle, BackoffCriteria, OverrideDeadline, Periodic, Persisted, RequiresCharging, PersistableBundle extras • Schedule the job with JobScheduler.schedule(jobBuilder.build())
main thread and expects to immediately return • If background work is needed, set it up to work on a background thread • Return = Am I doing stuff on a background thread? • When complete (successfully or on error), call jobFinished(JobParameters params, boolean needToReschedule) • onStopJob(JobParameters params) • Must stop your background thread if one is running. • Return = Do I need to reschedule this work according to the retry criteria set at creation time?