public abstract class Job
extends java.lang.Object
Job is executed in a background thread.| Modifier and Type | Class and Description |
|---|---|
protected 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. |
static boolean |
completeWakefulIntent(android.content.Intent intent)
Delegates calls to
WakefulBroadcastReceiver#completeWakefulIntent(Intent). |
boolean |
equals(java.lang.Object o) |
protected android.content.Context |
getContext() |
protected Job.Params |
getParams() |
int |
hashCode() |
protected boolean |
isCanceled() |
boolean |
isFinished() |
protected boolean |
isRequirementChargingMet() |
protected boolean |
isRequirementDeviceIdleMet() |
protected boolean |
isRequirementNetworkTypeMet() |
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.
|
protected android.content.ComponentName |
startWakefulService(android.content.Intent intent)
Delegates calls to
WakefulBroadcastReceiver#startWakefulService(Context, Intent). |
java.lang.String |
toString() |
protected abstract Job.Result onRunJob(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 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 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 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.protected final Job.Params getParams()
onRunJob(Params).protected final android.content.Context getContext()
Context running this Job. In most situations it's a Service.
If this context already was destroyed for some reason, then the application context is returned.
Never returns null.public final void cancel()
Job if it hasn't finished, yet.protected final boolean isCanceled()
true if this Job was canceled.public final boolean isFinished()
true if the Job finished.protected android.content.ComponentName startWakefulService(android.content.Intent intent)
WakefulBroadcastReceiver#startWakefulService(Context, Intent).
Context.startService, but holding a wake lock while the service starts.
This will modify the Intent to hold an extra identifying the wake lock;
when the service receives it in Service.onStartCommand, it should pass back the Intent it receives there to
completeWakefulIntent(android.content.Intent) in order to release
the wake lock.intent - The Intent with which to start the service, as per
Context.startService.WakefulBroadcastReceiverpublic static boolean completeWakefulIntent(android.content.Intent intent)
WakefulBroadcastReceiver#completeWakefulIntent(Intent).
startWakefulService(android.content.Intent). Any wake lock
that was being held will now be released.intent - The Intent as originally generated by startWakefulService(android.content.Intent).WakefulBroadcastReceiverpublic boolean equals(java.lang.Object o)
equals in class java.lang.Objectpublic int hashCode()
hashCode in class java.lang.Objectpublic java.lang.String toString()
toString in class java.lang.Object