Constructor and Description |
---|
Builder(int jobId,
ComponentName jobService)
Initialize a new Builder to construct a
JobInfo . |
Modifier and Type | Method and Description |
---|---|
JobInfo.Builder |
addTriggerContentUri(JobInfo.TriggerContentUri uri)
Add a new content: URI that will be monitored with a
ContentObserver , and will cause the job to execute if changed. |
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 |
setFlags(int flags) |
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 |
setPeriodic(long intervalMillis,
long flexMillis)
Specify that this job should recur with the provided interval and flex.
|
JobInfo.Builder |
setPersisted(boolean isPersisted)
Set whether or not to persist this job across device reboots.
|
JobInfo.Builder |
setPriority(int priority) |
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.
|
JobInfo.Builder |
setTriggerContentMaxDelay(long durationMs)
Set the maximum total delay (in milliseconds) that is allowed from the first
time a content change is detected until the job is scheduled.
|
JobInfo.Builder |
setTriggerContentUpdateDelay(long durationMs)
Set the delay (in milliseconds) from when a content change is detected until
the job is scheduled.
|
public Builder(int jobId, ComponentName jobService)
JobInfo
.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. This ID must be unique across all clients of the same uid
(not just the same package). You will want to make sure this is a stable
id across app updates, so probably not based on a resource ID.jobService
- The endpoint that you implement that will receive the callback from the
JobScheduler.public JobInfo.Builder setPriority(int priority)
public JobInfo.Builder setFlags(int flags)
public JobInfo.Builder setExtras(PersistableBundle extras)
extras
- Bundle containing extras you want the scheduler to hold on to for you.public JobInfo.Builder setRequiredNetworkType(int networkType)
JobInfo.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)
requiresCharging
- Whether or not the device is plugged in.public JobInfo.Builder setRequiresDeviceIdle(boolean requiresDeviceIdle)
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.
requiresDeviceIdle
- Whether or not the device need be within an idle maintenance
window.public JobInfo.Builder addTriggerContentUri(JobInfo.TriggerContentUri uri)
ContentObserver
, and will cause the job to execute if changed.
If you have any trigger content URIs associated with a job, it will not execute until
there has been a change report for one or more of them.
Note that trigger URIs can not be used in combination with
setPeriodic(long)
or setPersisted(boolean)
. To continually monitor
for content changes, you need to schedule a new JobInfo observing the same URIs
before you finish execution of the JobService handling the most recent changes.
Because because setting this property is not compatible with periodic or
persisted jobs, doing so will throw an IllegalArgumentException
when
build()
is called.
The following example shows how this feature can be used to monitor for changes in the photos on a device.
uri
- The content: URI to monitor.public JobInfo.Builder setTriggerContentUpdateDelay(long durationMs)
durationMs
- Delay after most recent content change, in milliseconds.public JobInfo.Builder setTriggerContentMaxDelay(long durationMs)
durationMs
- Delay after initial content change, in milliseconds.public JobInfo.Builder setPeriodic(long intervalMillis)
setMinimumLatency(long)
or
setOverrideDeadline(long)
will result in an error.intervalMillis
- Millisecond interval for which this job will repeat.public JobInfo.Builder setPeriodic(long intervalMillis, long flexMillis)
intervalMillis
- Millisecond interval for which this job will repeat. A minimum
value of JobInfo.getMinPeriodMillis()
is enforced.flexMillis
- Millisecond flex for this job. Flex is clamped to be at least
JobInfo.getMinFlexMillis()
or 5 percent of the period, whichever is
higher.public JobInfo.Builder setMinimumLatency(long minLatencyMillis)
IllegalArgumentException
when
build()
is called.minLatencyMillis
- Milliseconds before which this job will not be considered for
execution.public JobInfo.Builder setOverrideDeadline(long maxExecutionDelayMillis)
IllegalArgumentException
when
build()
is called.public JobInfo.Builder setBackoffCriteria(long initialBackoffMillis, int backoffPolicy)
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
JobService.jobFinished(android.app.job.JobParameters, boolean)
for more description of the return value for the case of a job executing while in idle
mode.initialBackoffMillis
- Millisecond time interval to wait initially when job has
failed.backoffPolicy
- is one of JobInfo.BACKOFF_POLICY_LINEAR
or
JobInfo.BACKOFF_POLICY_EXPONENTIAL
public JobInfo.Builder setPersisted(boolean isPersisted)
android.Manifest.permission#RECEIVE_BOOT_COMPLETED
. Otherwise an exception will
be thrown.isPersisted
- True to indicate that the job will be written to disk and loaded at
boot.public JobInfo build()