public final class JobRequest extends Object
Job
. Use the JobRequest.Builder
to create an instance.
Once built you can either call schedule()
or JobManager.schedule(JobRequest)
to schedule the request.Modifier and Type | Class and Description |
---|---|
static class |
JobRequest.BackoffPolicy |
static class |
JobRequest.Builder
Builder class for constructing JobRequests.
|
static interface |
JobRequest.JobScheduledCallback
Callback that is used when scheduling a
JobRequest asynchronously on a background thread. |
static class |
JobRequest.NetworkType |
Modifier and Type | Field and Description |
---|---|
static long |
DEFAULT_BACKOFF_MS
If you don't change the back-off ms, then 30 seconds are used as default.
|
static JobRequest.BackoffPolicy |
DEFAULT_BACKOFF_POLICY
If you don't change the back-off policy, then EXPONENTIAL is used as default.
|
static JobRequest.JobScheduledCallback |
DEFAULT_JOB_SCHEDULED_CALLBACK
The default callback that is used when you schedule a
JobRequest asynchronously in
scheduleAsync() . |
static JobRequest.NetworkType |
DEFAULT_NETWORK_TYPE
If you don't change the required network type, then no connection is required.
|
static long |
MIN_FLEX
The minimum flex of a periodic job.
|
static long |
MIN_INTERVAL
The minimum interval of a periodic job.
|
(package private) static long |
START_NOW |
Modifier and Type | Method and Description |
---|---|
JobRequest.Builder |
cancelAndEdit()
Cancel this request if it has been scheduled.
|
(package private) JobRequest.Builder |
createBuilder() |
boolean |
equals(Object o) |
(package private) static JobRequest |
fromCursor(Cursor cursor) |
long |
getBackoffMs()
Only valid if the job isn't periodic.
|
(package private) long |
getBackoffOffset() |
JobRequest.BackoffPolicy |
getBackoffPolicy()
Only valid if the job isn't periodic.
|
long |
getEndMs()
Only valid if the job isn't periodic.
|
PersistableBundleCompat |
getExtras() |
int |
getFailureCount()
|
long |
getFlexMs()
Flex time for this job.
|
long |
getIntervalMs()
Only valid if the job is periodic.
|
(package private) JobApi |
getJobApi() |
int |
getJobId() |
long |
getLastRun()
Returns the time the job did run the last time.
|
(package private) static long |
getMinFlex() |
(package private) static long |
getMinInterval() |
long |
getScheduledAt()
Returns the time when this job was scheduled.
|
long |
getStartMs()
Only valid if the job isn't periodic.
|
String |
getTag() |
Bundle |
getTransientExtras()
Returns the transient extras you passed in when constructing this job with
JobRequest.Builder.setTransientExtras(Bundle) . |
int |
hashCode() |
boolean |
hasRequirements() |
boolean |
isExact() |
(package private) boolean |
isFlexSupport() |
boolean |
isPeriodic() |
(package private) boolean |
isStarted()
Only non-periodic jobs can be in a started state.
|
boolean |
isTransient()
Returns whether this is a transient jobs.
|
boolean |
isUpdateCurrent() |
JobRequest.NetworkType |
requiredNetworkType() |
boolean |
requirementsEnforced() |
boolean |
requiresBatteryNotLow() |
boolean |
requiresCharging() |
boolean |
requiresDeviceIdle() |
boolean |
requiresStorageNotLow() |
(package private) JobRequest |
reschedule(boolean failure,
boolean newJob) |
int |
schedule()
Schedule a request which will be executed in the future.
|
void |
scheduleAsync()
Helper method to schedule a request on a background thread.
|
void |
scheduleAsync(JobRequest.JobScheduledCallback callback)
Helper method to schedule a request on a background thread.
|
(package private) void |
setFlexSupport(boolean flexSupport) |
(package private) void |
setScheduledAt(long timeStamp) |
(package private) void |
setStarted(boolean started) |
(package private) ContentValues |
toContentValues() |
String |
toString() |
(package private) void |
updateStats(boolean incFailureCount,
boolean updateLastRun) |
public static final long DEFAULT_BACKOFF_MS
Builder#setBackoffCriteria(long, BackoffPolicy)
,
Constant Field Valuespublic static final JobRequest.BackoffPolicy DEFAULT_BACKOFF_POLICY
Builder#setBackoffCriteria(long, BackoffPolicy)
public static final JobRequest.NetworkType DEFAULT_NETWORK_TYPE
Builder#setRequiredNetworkType(NetworkType)
,
JobRequest.Builder.setRequirementsEnforced(boolean)
public static final JobRequest.JobScheduledCallback DEFAULT_JOB_SCHEDULED_CALLBACK
JobRequest
asynchronously in
scheduleAsync()
. This implementation only logs a message in case of a failure and
doesn't crash.public static final long MIN_INTERVAL
JobScheduler
starting with Android Nougat. You can read
here more about
the limit.public static final long MIN_FLEX
JobScheduler
starting with Android Nougat. You can read
here more about
the limit.static final long START_NOW
static long getMinInterval()
static long getMinFlex()
public int getJobId()
@NonNull public String getTag()
Job
.public long getStartMs()
public long getEndMs()
public JobRequest.BackoffPolicy getBackoffPolicy()
public long getBackoffMs()
getBackoffPolicy()
if the job fails multiple times.public boolean isPeriodic()
public long getIntervalMs()
public long getFlexMs()
public boolean requirementsEnforced()
true
, then all requirements are checked before the job runs. If one requirement
isn't met, then the job is rescheduled right away.public boolean requiresCharging()
true
, then the job should only run if the device is charging.public boolean requiresDeviceIdle()
true
, then the job should only run if the device is idle.public boolean requiresBatteryNotLow()
true
, then the job should only run if the battery isn't low.public boolean requiresStorageNotLow()
true
, then the job should only run if the battery isn't low.public JobRequest.NetworkType requiredNetworkType()
public boolean hasRequirements()
public PersistableBundleCompat getExtras()
public boolean isUpdateCurrent()
true
, then this request will overwrite any preexisting jobs.public boolean isExact()
true
, then the job will run at exact time ignoring the device state.long getBackoffOffset()
JobApi getJobApi()
void setScheduledAt(long timeStamp)
public long getScheduledAt()
public int getFailureCount()
Job
was rescheduled or if a periodic
Job
wasn't successful.boolean isStarted()
boolean isFlexSupport()
void setFlexSupport(boolean flexSupport)
public long getLastRun()
public boolean isTransient()
@NonNull public Bundle getTransientExtras()
JobRequest.Builder.setTransientExtras(Bundle)
. WARNING: It's not guaranteed that a transient job
will run at all, e.g. rebooting the device or force closing the app will cancel the
job.
null
. If you did not set any extras this will be an empty bundle.
The returned bundle will also be empty, if the request isn't cached anymore.public int schedule()
JobRequest
, call cancelAndEdit()
, update your parameters and call
this method again. Calling this method on the same request instance multiple times without
cancelling is idempotent.
JobManager.schedule(JobRequest)
and getJobId()
for this request.public void scheduleAsync()
public void scheduleAsync(@NonNull JobRequest.JobScheduledCallback callback)
callback
- The callback which is invoked after the request has been scheduled.public JobRequest.Builder cancelAndEdit()
JobRequest.Builder createBuilder()
JobRequest reschedule(boolean failure, boolean newJob)
void updateStats(boolean incFailureCount, boolean updateLastRun)
void setStarted(boolean started)
ContentValues toContentValues()
static JobRequest fromCursor(Cursor cursor)