Modifier and Type | Class and Description |
---|---|
static class |
Job.Params
Holds several parameters for the
Job execution. |
static class |
Job.Result |
Constructor and Description |
---|
Job() |
Modifier and Type | Method and Description |
---|---|
void |
cancel()
Cancel this
Job if it hasn't finished, yet. |
(package private) void |
cancel(boolean deleted) |
boolean |
equals(Object o) |
protected Context |
getContext() |
(package private) long |
getFinishedTimeStamp() |
protected Job.Params |
getParams() |
(package private) Job.Result |
getResult() |
int |
hashCode() |
protected boolean |
isCanceled() |
(package private) boolean |
isDeleted() |
boolean |
isFinished() |
protected boolean |
isRequirementBatteryNotLowMet() |
protected boolean |
isRequirementChargingMet() |
protected boolean |
isRequirementDeviceIdleMet() |
protected boolean |
isRequirementNetworkTypeMet() |
protected boolean |
isRequirementStorageNotLowMet() |
protected boolean |
meetsRequirements()
Checks all requirements for this job.
|
(package private) boolean |
meetsRequirements(boolean checkRequirementsEnforced) |
protected void |
onCancel()
This method is intended to be overwritten.
|
protected void |
onReschedule(int newJobId)
This method is called if you returned
Job.Result.RESCHEDULE in onRunJob(Params)
and the Job was successfully rescheduled. |
protected abstract Job.Result |
onRunJob(Job.Params params)
This method is invoked from a background thread.
|
(package private) Job.Result |
runJob() |
(package private) Job |
setContext(Context context) |
(package private) Job |
setRequest(JobRequest request,
Bundle transientExtras) |
String |
toString() |
@NonNull @WorkerThread protected abstract Job.Result onRunJob(@NonNull Job.Params params)
Job
is instantiated. You can identify your Job
with the passed params
.
isCanceled()
frequently for long running jobs and stop your
task if necessary.
PowerManager.WakeLock
is acquired for 3 minutes for each Job
. If your task
needs more time, then you need to create an extra PowerManager.WakeLock
.params
- The parameters for this concrete job.Job
. Note that returning Job.Result.RESCHEDULE
for a periodic
Job
is invalid and ignored.protected void onCancel()
isCanceled()
.isCanceled()
final Job.Result runJob()
@WorkerThread protected void onReschedule(int newJobId)
Job.Result.RESCHEDULE
in onRunJob(Params)
and the Job
was successfully rescheduled. The new rescheduled JobRequest
has
a new ID. Override this method if you want to be notified about the change.newJobId
- The new ID of the rescheduled JobRequest
.protected boolean meetsRequirements()
boolean meetsRequirements(boolean checkRequirementsEnforced)
protected boolean isRequirementChargingMet()
false
if the Job
requires the device to be charging and it isn't charging.
Otherwise always returns true
.protected boolean isRequirementDeviceIdleMet()
false
if the Job
requires the device to be idle and it isn't idle. Otherwise
always returns true
.protected boolean isRequirementBatteryNotLowMet()
protected boolean isRequirementStorageNotLowMet()
protected boolean isRequirementNetworkTypeMet()
false
if the Job
requires the device to be in a specific network state and it
isn't in this state. Otherwise always returns true
.final Job setRequest(JobRequest request, @NonNull Bundle transientExtras)
@NonNull protected final Job.Params getParams()
onRunJob(Params)
.public final void cancel()
Job
if it hasn't finished, yet.final void cancel(boolean deleted)
protected final boolean isCanceled()
true
if this Job
was canceled.public final boolean isFinished()
true
if the Job
finished.final long getFinishedTimeStamp()
final Job.Result getResult()
final boolean isDeleted()