public static final class JobRequest.Builder
extends java.lang.Object
| Constructor and Description |
|---|
Builder(java.lang.String tag)
Creates a new instance to build a
JobRequest. |
| Modifier and Type | Method and Description |
|---|---|
JobRequest |
build() |
boolean |
equals(java.lang.Object o) |
int |
hashCode() |
JobRequest.Builder |
setBackoffCriteria(long backoffMs,
JobRequest.BackoffPolicy backoffPolicy)
Change the back-off policy for a non periodic job.
|
JobRequest.Builder |
setExact(long exactMs)
Specify that the job should run at an exact time.
|
JobRequest.Builder |
setExecutionWindow(long startMs,
long endMs)
Set the time window when the job will be run.
|
JobRequest.Builder |
setExtras(PersistableBundleCompat extras)
Set optional extras.
|
JobRequest.Builder |
setPeriodic(long intervalMs)
Specify that this job should recur with the provided interval, not more than once per period.
|
JobRequest.Builder |
setPeriodic(long intervalMs,
long flexMs)
Specify that this job should recur with the provided interval and flex, not more than once per period.
|
JobRequest.Builder |
setPersisted(boolean persisted)
Set whether the job should be persisted across reboots.
|
JobRequest.Builder |
setRequiredNetworkType(JobRequest.NetworkType networkType)
Set some description of the kind of network type your job needs to have.
|
JobRequest.Builder |
setRequirementsEnforced(boolean enforced)
It's possible to set several requirements for a job, however, not all of them need to
be considered by the underlying
JobApi. |
JobRequest.Builder |
setRequiresCharging(boolean requiresCharging)
Specify that to run this job, the device needs to be plugged in.
|
JobRequest.Builder |
setRequiresDeviceIdle(boolean requiresDeviceIdle)
Specify that to run, the job needs the device to be in idle mode.
|
JobRequest.Builder |
setUpdateCurrent(boolean updateCurrent)
Sets whether this request should overwrite any preexisting jobs with the same tag.
|
public Builder(java.lang.String tag)
JobRequest. Note that the tag doesn't
need to be unique. Each created request has an unique ID to differentiate between jobs
with the same tag.
JobCreator to create
a Job for this tag.tag - The tag is used to identify your Job in JobCreator.create(String).public JobRequest.Builder setExecutionWindow(long startMs, long endMs)
setPeriodic(long) or setExact(long). For those types jobs it doesn't
make sense to have a time window.
System.currentTimeMillis() + startMs and
System.currentTimeMillis() + endMs.
Long.MAX_VALUE / 3 * 2 (about 53_375_995_583 days).
Otherwise some APIs schedule the job immediately. No exception is thrown if an argument is greater
than the maximum value, the arguments are silently being clamped.
AlarmManager used
as fallback API doesn't allow setting a start date. Although being inexact, the execution time is
the arithmetic average of startMs and endMs. The result could be that your job never
runs on pre Android 5.0 devices, if one argument is too large.startMs - Earliest point from which your task is eligible to run.endMs - Latest point at which your task must be run.public JobRequest.Builder setExtras(PersistableBundleCompat extras)
extras - Bundle containing extras which you can retrieve with Job.Params.getExtras().public JobRequest.Builder setRequirementsEnforced(boolean enforced)
JobApi. If the requirements are enforced, then
the device state is checked before your job runs. If at least one requirement isn't met,
then the job is rescheduled and not run.
false. The Job class provides several methods, e.g.
Job.isRequirementChargingMet().
false.enforced - If true, then all set requirements are manually checked.public JobRequest.Builder setRequiredNetworkType(JobRequest.NetworkType networkType)
JobRequest.NetworkType.ANY.
networkType - The required network type.setRequirementsEnforced(boolean),
setExecutionWindow(long, long)public JobRequest.Builder setRequiresCharging(boolean requiresCharging)
false.
requiresCharging - Whether or not the device needs to be plugged in.setRequirementsEnforced(boolean),
setExecutionWindow(long, long)public JobRequest.Builder setRequiresDeviceIdle(boolean requiresDeviceIdle)
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.
requiresDeviceIdle - Whether or not the device needs be idle.setRequirementsEnforced(boolean),
setExecutionWindow(long, long)public JobRequest.Builder setExact(long exactMs)
false. Internally an exact job is always using the
AlarmManager.
System.currentTimeMillis() + exactMs.
Long.MAX_VALUE / 3 * 2 (about 53_375_995_583 days).
No exception is thrown if the argument is greater than the maximum value, the argument is
silently being clamped.exactMs - The exact offset when the job should run from when the job was scheduled.AlarmManager.setExact(int, long, android.app.PendingIntent),
AlarmManager.setExactAndAllowWhileIdle(int, long, android.app.PendingIntent)public JobRequest.Builder setPeriodic(long intervalMs)
Job.Result.RESCHEDULE is ignored for periodic jobs,
setting a back-off criteria is illegal as well.intervalMs - The job should run at most once every intervalMs. The minimum value is 15min.public JobRequest.Builder setPeriodic(long intervalMs, long flexMs)
Job.Result.RESCHEDULE is ignored for
periodic jobs, setting a back-off criteria is illegal as well.intervalMs - The job should run at most once every intervalMs. The minimum value is 15min.flexMs - How close to the end of the period the job should run. The minimum value is 5min.JobRequest.MIN_INTERVAL,
JobRequest.MIN_FLEXpublic JobRequest.Builder setBackoffCriteria(long backoffMs, JobRequest.BackoffPolicy backoffPolicy)
JobRequest.BackoffPolicy.EXPONENTIAL. The time is increasing each time a job fails and
returns Job.Result.RESCHEDULE, but capped at 5 hours.
backoffMs - The initial interval to wait when the job has been rescheduled.backoffPolicy - Is either JobRequest.BackoffPolicy.LINEAR or JobRequest.BackoffPolicy.EXPONENTIAL.Job.Result.RESCHEDULE,
Job.onReschedule(int)public JobRequest.Builder setPersisted(boolean persisted)
Manifest.permission.RECEIVE_BOOT_COMPLETED. Otherwise an exception will
be thrown. The default is set to false.persisted - If true the job is scheduled after a reboot.public JobRequest.Builder setUpdateCurrent(boolean updateCurrent)
true,
then this request calls JobManager.cancelAllForTag(String) with the given tag before
being scheduled.updateCurrent - If {code true} this request will cancel any preexisting job with the same tag
while being scheduled.public JobRequest build()
JobRequest with this parameters to hand to the JobManager.public boolean equals(java.lang.Object o)
equals in class java.lang.Objectpublic int hashCode()
hashCode in class java.lang.Object