Android APIs
public static final class

JobInfo.Builder

extends Object
java.lang.Object
   ↳ android.app.job.JobInfo.Builder

Class Overview

Builder class for constructing JobInfo objects.

Summary

Public Constructors
JobInfo.Builder(int jobId, ComponentName jobService)
Public Methods
JobInfo build()
JobInfo.Builder setBackoffCriteria(long initialBackoffMillis, int backoffPolicy)
Set up the back-off/retry policy.
JobInfo.Builder setExtras(PersistableBundle extras)
Set optional extras.
JobInfo.Builder setMinimumLatency(long minLatencyMillis)
Specify that this job should be delayed by the provided amount of time.
JobInfo.Builder setOverrideDeadline(long maxExecutionDelayMillis)
Set deadline which is the maximum scheduling latency.
JobInfo.Builder setPeriodic(long intervalMillis)
Specify that this job should recur with the provided interval, not more than once per period.
JobInfo.Builder setPersisted(boolean isPersisted)
Set whether or not to persist this job across device reboots.
JobInfo.Builder setRequiredNetworkType(int networkType)
Set some description of the kind of network type your job needs to have.
JobInfo.Builder setRequiresCharging(boolean requiresCharging)
Specify that to run this job, the device needs to be plugged in.
JobInfo.Builder setRequiresDeviceIdle(boolean requiresDeviceIdle)
Specify that to run, the job needs the device to be in idle mode.
[Expand]
Inherited Methods
From class java.lang.Object

Public Constructors

public JobInfo.Builder (int jobId, ComponentName jobService)

Added in API level 21

Parameters
jobId Application-provided id for this job. Subsequent calls to cancel, or jobs created with the same jobId, will update the pre-existing job with the same id.
jobService The endpoint that you implement that will receive the callback from the JobScheduler.

Public Methods

public JobInfo build ()

Added in API level 21

Returns
  • The job object to hand to the JobScheduler. This object is immutable.

public JobInfo.Builder setBackoffCriteria (long initialBackoffMillis, int backoffPolicy)

Added in API level 21

Set up the back-off/retry policy. This defaults to some respectable values: {30 seconds, Exponential}. We cap back-off at 5hrs. Note that trying to set a backoff criteria for a job with setRequiresDeviceIdle(boolean) will throw an exception when you call build(). This is because back-off typically does not make sense for these types of jobs. See jobFinished(android.app.job.JobParameters, boolean) for more description of the return value for the case of a job executing while in idle mode.

Parameters
initialBackoffMillis Millisecond time interval to wait initially when job has failed.
backoffPolicy is one of BACKOFF_POLICY_LINEAR or BACKOFF_POLICY_EXPONENTIAL

public JobInfo.Builder setExtras (PersistableBundle extras)

Added in API level 21

Set optional extras. This is persisted, so we only allow primitive types.

Parameters
extras Bundle containing extras you want the scheduler to hold on to for you.

public JobInfo.Builder setMinimumLatency (long minLatencyMillis)

Added in API level 21

Specify that this job should be delayed by the provided amount of time. Because it doesn't make sense setting this property on a periodic job, doing so will throw an IllegalArgumentException when build() is called.

Parameters
minLatencyMillis Milliseconds before which this job will not be considered for execution.

public JobInfo.Builder setOverrideDeadline (long maxExecutionDelayMillis)

Added in API level 21

Set deadline which is the maximum scheduling latency. The job will be run by this deadline even if other requirements are not met. Because it doesn't make sense setting this property on a periodic job, doing so will throw an IllegalArgumentException when build() is called.

public JobInfo.Builder setPeriodic (long intervalMillis)

Added in API level 21

Specify that this job should recur with the provided interval, not more than once per period. You have no control over when within this interval this job will be executed, only the guarantee that it will be executed at most once within this interval. Setting this function on the builder with setMinimumLatency(long) or setOverrideDeadline(long) will result in an error.

Parameters
intervalMillis Millisecond interval for which this job will repeat.

public JobInfo.Builder setPersisted (boolean isPersisted)

Added in API level 21

Set whether or not to persist this job across device reboots. This will only have an effect if your application holds the permission RECEIVE_BOOT_COMPLETED. Otherwise an exception will be thrown.

Parameters
isPersisted True to indicate that the job will be written to disk and loaded at boot.

public JobInfo.Builder setRequiredNetworkType (int networkType)

Added in API level 21

Set some description of the kind of network type your job needs to have. Not calling this function means the network is not necessary, as the default is NETWORK_TYPE_NONE. Bear in mind that calling this function defines network as a strict requirement for your job. If the network requested is not available your job will never run. See setOverrideDeadline(long) to change this behaviour.

public JobInfo.Builder setRequiresCharging (boolean requiresCharging)

Added in API level 21

Specify that to run this job, the device needs to be plugged in. This defaults to false.

Parameters
requiresCharging Whether or not the device is plugged in.

public JobInfo.Builder setRequiresDeviceIdle (boolean requiresDeviceIdle)

Added in API level 21

Specify that to run, the job needs the device to be in idle mode. This defaults to false.

Idle mode is a loose definition provided by the system, which means that the device is not in use, and has not been in use for some time. As such, it is a good time to perform resource heavy jobs. Bear in mind that battery usage will still be attributed to your application, and surfaced to the user in battery stats.

Parameters
requiresDeviceIdle Whether or not the device need be within an idle maintenance window.