JobScheduler
public
abstract
class
JobScheduler
extends Object↳
android.app.job.JobScheduler
This is an API for scheduling various types of jobs against the framework that will be executed
in your application's own process.
See
The framework will be intelligent about when it executes jobs, and attempt to batch
and defer them as much as possible. Typically if you don't specify a deadline on a job, it
can be run at any moment depending on the current state of the JobScheduler's internal queue.
While a job is running, the system holds a wakelock on behalf of your app. For this reason,
you do not need to take any action to guarantee that the device stays awake for the
duration of the job.
You do not
instantiate this class directly; instead, retrieve it through
Prior to Android version
In Android version
Note: Beginning with API 30
(
Summary
Constants
int
Returned from
int
Returned from
Public constructors
Public methods
abstract
void
cancel(int jobId)
Cancel the specified job.
abstract
void
Cancel all jobs that have been scheduled by the calling application.
abstract
int
Similar to or existing
job.
Retrieve all jobs that have been scheduled by the calling application.
abstract
JobInfo
Look up the description of a scheduled job.
abstract
int
Schedule a job to be executed.
Inherited methods
Creates and returns a copy of this object.
boolean
Indicates whether some other object is "equal to" this one.
void
Called by the garbage collector on an object when garbage collection
determines that there are no more references to the object.
final
Class>
Returns the runtime class of this Object.
int
Returns a hash code value for the object.
final
void
Wakes up a single thread that is waiting on this object's
monitor.
final
void
Wakes up all threads that are waiting on this object's monitor.
Returns a string representation of the object.
final
void
wait(long timeout, int nanos)
Causes the current thread to wait until another thread invokes the
final
void
wait(long timeout)
Causes the current thread to wait until either another thread invokes the
final
void
Causes the current thread to wait until another thread invokes the
Constants
RESULT_FAILURE
public static final int RESULT_FAILURE
Returned froman invalid parameter was supplied (eg. the run-time for your job is too short, or the
system can't resolve the requisite
the app has too many jobs scheduled
the app has tried to schedule too many jobs in a short amount of time
Attempting to schedule the job again immediately after receiving this result will not
guarantee a successful schedule.
Constant Value:
0
(0x00000000)
RESULT_SUCCESS
public static final int RESULT_SUCCESS
Returned from
Constant Value:
1
(0x00000001)
Public constructors
JobScheduler
public JobScheduler ()
Public methods
cancel
public abstract void cancel (int jobId)
Cancel the specified job. If the job is currently executing, it is stopped
immediately and the return value from its
Parameters
jobId
int: unique identifier for the job to be canceled, as supplied to
cancelAll
public abstract void cancelAll ()
Cancel all jobs that have been scheduled by the calling application.
enqueue
public abstract int enqueue (JobInfo job,
JobWorkItem work)
Similar to or existing
job. If a job with the same ID is already scheduled, it will be replaced with the
new
The work you enqueue is later retrieved through
It is strongly encouraged that you use the same
It is recommended that you avoid using
Note: Scheduling a job can have a high cost, even if it's
rescheduling the same job and the job didn't execute, especially on platform versions before
version
Note: The JobService component needs to be enabled in order to successfully schedule a
job.
Parameters
job
JobInfo: The job you wish to enqueue work for. See
null.
work
JobWorkItem: New work to enqueue. This will be available later when the job starts running.
This value cannot be null.
Returns
int
the result of the enqueue request.
Value is
Throws
if the specified
getAllPendingJobs
public abstract List getAllPendingJobs ()
Retrieve all jobs that have been scheduled by the calling application.
Returns
a list of all of the app's scheduled jobs. This includes jobs that are
currently started as well as those that are still waiting to run.
This value cannot be null.
getPendingJob
public abstract JobInfo getPendingJob (int jobId)
Look up the description of a scheduled job.
Parameters
jobId
int
Returns
The null
if the supplied job ID does not correspond to any job.
schedule
public abstract int schedule (JobInfo job)
Schedule a job to be executed. Will replace any currently scheduled job with the same
ID with the new information in the
Note: Scheduling a job can have a high cost, even if it's
rescheduling the same job and the job didn't execute, especially on platform versions before
version
Note: The JobService component needs to be enabled in order to successfully schedule a
job.
Parameters
job
JobInfo: The job you wish scheduled. See
null.
Returns
int
the result of the schedule request.
Value is
Throws
if the specified