Added in [API level 21](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels) Summary: [Constants](https://developer.android.com/reference/android/app/job/JobScheduler#constants) \| [Ctors](https://developer.android.com/reference/android/app/job/JobScheduler#pubctors) \| [Methods](https://developer.android.com/reference/android/app/job/JobScheduler#pubmethods) \| [Inherited Methods](https://developer.android.com/reference/android/app/job/JobScheduler#inhmethods)

# JobScheduler

*** ** * ** ***


`
public


abstract
class
JobScheduler
`


`

extends https://developer.android.com/reference/java/lang/Object


`

`


`

|---|---|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object) ||
| ↳ | android.app.job.JobScheduler |

<br />

*** ** * ** ***

This is an API for scheduling various types of jobs against the framework that will be executed
in your application's own process.


See `https://developer.android.com/reference/android/app/job/JobInfo` for more description of the types of jobs that can be run
and how to construct them. You will construct these JobInfo objects and pass them to the
JobScheduler with `https://developer.android.com/reference/android/app/job/JobScheduler#schedule(android.app.job.JobInfo)`. When the criteria declared are met, the
system will execute this job on your application's `https://developer.android.com/reference/android/app/job/JobService`.
You identify the service component that implements the logic for your job when you
construct the JobInfo using
`https://developer.android.com/reference/android/app/job/JobInfo.Builder#Builder(int,%20android.content.ComponentName)`.


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.


Starting in Android version `https://developer.android.com/reference/android/os/Build.VERSION_CODES#UPSIDE_DOWN_CAKE`,
JobScheduler may try to optimize job execution by shifting execution to times with more available
system resources in order to lower user impact. Factors in system health include sufficient
battery, idle, charging, and access to an un-metered network. Jobs will initially be treated as
if they have all these requirements, but as their deadlines approach, restrictions will become
less strict. Requested requirements will not be affected by this change.


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
`https://developer.android.com/reference/android/content/Context#getSystemService(java.lang.Class<T>)`.

Prior to Android version `https://developer.android.com/reference/android/os/Build.VERSION_CODES#S`, jobs could only have
a maximum of 100 jobs scheduled at a time. Starting with Android version
`https://developer.android.com/reference/android/os/Build.VERSION_CODES#S`, that limit has been increased to 150.
Expedited jobs also count towards the limit.

In Android version `https://developer.android.com/reference/android/os/Build.VERSION_CODES#LOLLIPOP`, jobs had a maximum
execution time of one minute. Starting with Android version
`https://developer.android.com/reference/android/os/Build.VERSION_CODES#M` and ending with Android version
`https://developer.android.com/reference/android/os/Build.VERSION_CODES#R`, jobs had a maximum execution time of 10 minutes.
Starting from Android version `https://developer.android.com/reference/android/os/Build.VERSION_CODES#S`, jobs will still be
stopped after 10 minutes if the system is busy or needs the resources, but if not, jobs
may continue running longer than 10 minutes.

**Note:** Beginning with API 30
(`https://developer.android.com/reference/android/os/Build.VERSION_CODES#R`), JobScheduler will throttle runaway applications.
Calling `https://developer.android.com/reference/android/app/job/JobScheduler#schedule(android.app.job.JobInfo)` and other such methods with very high frequency can have a
high cost and so, to make sure the system doesn't get overwhelmed, JobScheduler will begin
to throttle apps, regardless of target SDK version.
**See also:**

- `https://developer.android.com/reference/android/app/job/JobInfo.Builder#setRequiresBatteryNotLow(boolean)`
- `https://developer.android.com/reference/android/app/job/JobInfo.Builder#setRequiresDeviceIdle(boolean)`
- `https://developer.android.com/reference/android/app/job/JobInfo.Builder#setRequiresCharging(boolean)`
- `https://developer.android.com/reference/android/app/job/JobInfo.Builder#setRequiredNetworkType(int)`

## Summary

| ### Constants ||
|---|---|
| `int` | `https://developer.android.com/reference/android/app/job/JobScheduler#PENDING_JOB_REASON_APP` The app is in a state that prevents the job from running (eg. |
| `int` | `https://developer.android.com/reference/android/app/job/JobScheduler#PENDING_JOB_REASON_APP_STANDBY` The current standby bucket prevents the job from running. |
| `int` | `https://developer.android.com/reference/android/app/job/JobScheduler#PENDING_JOB_REASON_BACKGROUND_RESTRICTION` The app is restricted from running in the background. |
| `int` | `https://developer.android.com/reference/android/app/job/JobScheduler#PENDING_JOB_REASON_CONSTRAINT_BATTERY_NOT_LOW` The requested battery-not-low constraint is not satisfied. |
| `int` | `https://developer.android.com/reference/android/app/job/JobScheduler#PENDING_JOB_REASON_CONSTRAINT_CHARGING` The requested charging constraint is not satisfied. |
| `int` | `https://developer.android.com/reference/android/app/job/JobScheduler#PENDING_JOB_REASON_CONSTRAINT_CONNECTIVITY` The requested connectivity constraint is not satisfied. |
| `int` | `https://developer.android.com/reference/android/app/job/JobScheduler#PENDING_JOB_REASON_CONSTRAINT_CONTENT_TRIGGER` The requested content trigger constraint is not satisfied. |
| `int` | `https://developer.android.com/reference/android/app/job/JobScheduler#PENDING_JOB_REASON_CONSTRAINT_DEADLINE` The override deadline has not transpired. |
| `int` | `https://developer.android.com/reference/android/app/job/JobScheduler#PENDING_JOB_REASON_CONSTRAINT_DEVICE_IDLE` The requested idle constraint is not satisfied. |
| `int` | `https://developer.android.com/reference/android/app/job/JobScheduler#PENDING_JOB_REASON_CONSTRAINT_MINIMUM_LATENCY` The minimum latency has not transpired. |
| `int` | `https://developer.android.com/reference/android/app/job/JobScheduler#PENDING_JOB_REASON_CONSTRAINT_PREFETCH` The system's estimate of when the app will be launched is far away enough to warrant delaying this job. |
| `int` | `https://developer.android.com/reference/android/app/job/JobScheduler#PENDING_JOB_REASON_CONSTRAINT_STORAGE_NOT_LOW` The requested storage-not-low constraint is not satisfied. |
| `int` | `https://developer.android.com/reference/android/app/job/JobScheduler#PENDING_JOB_REASON_DEVICE_STATE` The job is being deferred due to the device state (e.g., Doze, battery saver, memory usage, thermal status, etc.). |
| `int` | `https://developer.android.com/reference/android/app/job/JobScheduler#PENDING_JOB_REASON_EXECUTING` The job is currently running and is therefore not pending. |
| `int` | `https://developer.android.com/reference/android/app/job/JobScheduler#PENDING_JOB_REASON_INVALID_JOB_ID` The job doesn't exist. |
| `int` | `https://developer.android.com/reference/android/app/job/JobScheduler#PENDING_JOB_REASON_JOB_SCHEDULER_OPTIMIZATION` JobScheduler thinks it can defer this job to a more optimal running time. |
| `int` | `https://developer.android.com/reference/android/app/job/JobScheduler#PENDING_JOB_REASON_QUOTA` The app has consumed all of its current quota. |
| `int` | `https://developer.android.com/reference/android/app/job/JobScheduler#PENDING_JOB_REASON_UNDEFINED` There is no known reason why the job is pending. |
| `int` | `https://developer.android.com/reference/android/app/job/JobScheduler#PENDING_JOB_REASON_USER` JobScheduler is respecting one of the user's actions (eg. |
| `int` | `https://developer.android.com/reference/android/app/job/JobScheduler#RESULT_FAILURE` Returned from `https://developer.android.com/reference/android/app/job/JobScheduler#schedule(android.app.job.JobInfo)` if a job wasn't scheduled successfully. |
| `int` | `https://developer.android.com/reference/android/app/job/JobScheduler#RESULT_SUCCESS` Returned from `https://developer.android.com/reference/android/app/job/JobScheduler#schedule(android.app.job.JobInfo)` if this job has been successfully scheduled. |

| ### Public constructors ||
|---|---|
| ` https://developer.android.com/reference/android/app/job/JobScheduler#JobScheduler()() ` |

| ### Public methods ||
|---|---|
| ` boolean` | ` https://developer.android.com/reference/android/app/job/JobScheduler#canRunUserInitiatedJobs()() ` Returns `true` if the calling app currently holds the `https://developer.android.com/reference/android/Manifest.permission#RUN_USER_INITIATED_JOBS` permission, allowing it to run user-initiated jobs. |
| ` abstract void` | ` https://developer.android.com/reference/android/app/job/JobScheduler#cancel(int)(int jobId) ` Cancel the specified job. |
| ` abstract void` | ` https://developer.android.com/reference/android/app/job/JobScheduler#cancelAll()() ` Cancel all jobs that have been scheduled in the current namespace by the calling application. |
| ` void` | ` https://developer.android.com/reference/android/app/job/JobScheduler#cancelInAllNamespaces()() ` Cancel *all* jobs that have been scheduled by the calling application, regardless of namespace. |
| ` abstract int` | ` https://developer.android.com/reference/android/app/job/JobScheduler#enqueue(android.app.job.JobInfo,%20android.app.job.JobWorkItem)(https://developer.android.com/reference/android/app/job/JobInfo job, https://developer.android.com/reference/android/app/job/JobWorkItem work) ` Similar to `https://developer.android.com/reference/android/app/job/JobScheduler#schedule(android.app.job.JobInfo)`, but allows you to enqueue work for a new *or existing* job. |
| ` https://developer.android.com/reference/android/app/job/JobScheduler` | ` https://developer.android.com/reference/android/app/job/JobScheduler#forNamespace(java.lang.String)(https://developer.android.com/reference/java/lang/String namespace) ` Get a JobScheduler instance that is dedicated to a specific namespace. |
| ` abstract https://developer.android.com/reference/java/util/List<https://developer.android.com/reference/android/app/job/JobInfo>` | ` https://developer.android.com/reference/android/app/job/JobScheduler#getAllPendingJobs()() ` Retrieve all jobs that have been scheduled by the calling application. |
| ` https://developer.android.com/reference/java/lang/String` | ` https://developer.android.com/reference/android/app/job/JobScheduler#getNamespace()() ` Get the namespace this JobScheduler instance is operating in. |
| ` abstract https://developer.android.com/reference/android/app/job/JobInfo` | ` https://developer.android.com/reference/android/app/job/JobScheduler#getPendingJob(int)(int jobId) ` Look up the description of a scheduled job. |
| ` int` | ` https://developer.android.com/reference/android/app/job/JobScheduler#getPendingJobReason(int)(int jobId) ` Returns a reason why the job is pending and not currently executing. |
| ` https://developer.android.com/reference/java/util/Map<https://developer.android.com/reference/java/lang/Integer, https://developer.android.com/reference/java/time/Duration>` | ` https://developer.android.com/reference/android/app/job/JobScheduler#getPendingJobReasonStats(int)(int jobId) ` For the given `jobId`, returns an aggregated view of why the job has been pending execution over its lifetime. |
| ` int[]` | ` https://developer.android.com/reference/android/app/job/JobScheduler#getPendingJobReasons(int)(int jobId) ` Returns potential reasons why the job with the given `jobId` may be pending and not currently executing. |
| ` https://developer.android.com/reference/java/util/List<https://developer.android.com/reference/android/app/job/PendingJobReasonsInfo>` | ` https://developer.android.com/reference/android/app/job/JobScheduler#getPendingJobReasonsHistory(int)(int jobId) ` For the given `jobId`, returns a limited historical view of why the job may have been pending execution. |
| ` https://developer.android.com/reference/java/util/Map<https://developer.android.com/reference/java/lang/String, https://developer.android.com/reference/java/util/List<https://developer.android.com/reference/android/app/job/JobInfo>>` | ` https://developer.android.com/reference/android/app/job/JobScheduler#getPendingJobsInAllNamespaces()() ` Retrieve all jobs that have been scheduled by the calling application within the current namespace. |
| ` abstract int` | ` https://developer.android.com/reference/android/app/job/JobScheduler#schedule(android.app.job.JobInfo)(https://developer.android.com/reference/android/app/job/JobInfo job) ` Schedule a job to be executed. |

| ### Inherited methods |
|---|---|
| From class ` https://developer.android.com/reference/java/lang/Object ` |---|---| | ` https://developer.android.com/reference/java/lang/Object` | ` https://developer.android.com/reference/java/lang/Object#clone()() ` Creates and returns a copy of this object. | | ` boolean` | ` https://developer.android.com/reference/java/lang/Object#equals(java.lang.Object)(https://developer.android.com/reference/java/lang/Object obj) ` Indicates whether some other object is "equal to" this one. | | ` void` | ` https://developer.android.com/reference/java/lang/Object#finalize()() ` Called by the garbage collector on an object when garbage collection determines that there are no more references to the object. | | ` final https://developer.android.com/reference/java/lang/Class<?>` | ` https://developer.android.com/reference/java/lang/Object#getClass()() ` Returns the runtime class of this `Object`. | | ` int` | ` https://developer.android.com/reference/java/lang/Object#hashCode()() ` Returns a hash code value for the object. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#notify()() ` Wakes up a single thread that is waiting on this object's monitor. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#notifyAll()() ` Wakes up all threads that are waiting on this object's monitor. | | ` https://developer.android.com/reference/java/lang/String` | ` https://developer.android.com/reference/java/lang/Object#toString()() ` Returns a string representation of the object. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#wait(long,%20int)(long timeoutMillis, int nanos) ` Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*, or until a certain amount of real time has elapsed. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#wait(long)(long timeoutMillis) ` Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*, or until a certain amount of real time has elapsed. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#wait()() ` Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*. | ||

## Constants

### PENDING_JOB_REASON_APP

Added in [API level 34](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final int PENDING_JOB_REASON_APP
```

The app is in a state that prevents the job from running
(eg. the `https://developer.android.com/reference/android/app/job/JobService` component is disabled).

<br />

Constant Value:

1
(0x00000001)


### PENDING_JOB_REASON_APP_STANDBY

Added in [API level 34](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final int PENDING_JOB_REASON_APP_STANDBY
```

The current standby bucket prevents the job from running.

<br />

**See also:**

- `https://developer.android.com/reference/android/app/usage/UsageStatsManager#STANDBY_BUCKET_RESTRICTED`

Constant Value:

2
(0x00000002)


### PENDING_JOB_REASON_BACKGROUND_RESTRICTION

Added in [API level 34](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final int PENDING_JOB_REASON_BACKGROUND_RESTRICTION
```

The app is restricted from running in the background.

<br />

**See also:**

- `https://developer.android.com/reference/android/app/ActivityManager#isBackgroundRestricted()`
- `https://developer.android.com/reference/android/content/pm/PackageManager#isInstantApp()`

Constant Value:

3
(0x00000003)


### PENDING_JOB_REASON_CONSTRAINT_BATTERY_NOT_LOW

Added in [API level 34](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final int PENDING_JOB_REASON_CONSTRAINT_BATTERY_NOT_LOW
```

The requested battery-not-low constraint is not satisfied.

<br />

**See also:**

- `https://developer.android.com/reference/android/app/job/JobInfo.Builder#setRequiresBatteryNotLow(boolean)`

Constant Value:

4
(0x00000004)


### PENDING_JOB_REASON_CONSTRAINT_CHARGING

Added in [API level 34](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final int PENDING_JOB_REASON_CONSTRAINT_CHARGING
```

The requested charging constraint is not satisfied.

<br />

**See also:**

- `https://developer.android.com/reference/android/app/job/JobInfo.Builder#setRequiresCharging(boolean)`

Constant Value:

5
(0x00000005)


### PENDING_JOB_REASON_CONSTRAINT_CONNECTIVITY

Added in [API level 34](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final int PENDING_JOB_REASON_CONSTRAINT_CONNECTIVITY
```

The requested connectivity constraint is not satisfied.

<br />

**See also:**

- `https://developer.android.com/reference/android/app/job/JobInfo.Builder#setRequiredNetwork(android.net.NetworkRequest)`
- `https://developer.android.com/reference/android/app/job/JobInfo.Builder#setRequiredNetworkType(int)`

Constant Value:

6
(0x00000006)


### PENDING_JOB_REASON_CONSTRAINT_CONTENT_TRIGGER

Added in [API level 34](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final int PENDING_JOB_REASON_CONSTRAINT_CONTENT_TRIGGER
```

The requested content trigger constraint is not satisfied.

<br />

**See also:**

- `https://developer.android.com/reference/android/app/job/JobInfo.Builder#addTriggerContentUri(android.app.job.JobInfo.TriggerContentUri)`

Constant Value:

7
(0x00000007)


### PENDING_JOB_REASON_CONSTRAINT_DEADLINE

Added in [API level 36](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final int PENDING_JOB_REASON_CONSTRAINT_DEADLINE
```

The override deadline has not transpired.

<br />

**See also:**

- `https://developer.android.com/reference/android/app/job/JobInfo.Builder#setOverrideDeadline(long)`

Constant Value:

16
(0x00000010)


### PENDING_JOB_REASON_CONSTRAINT_DEVICE_IDLE

Added in [API level 34](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final int PENDING_JOB_REASON_CONSTRAINT_DEVICE_IDLE
```

The requested idle constraint is not satisfied.

<br />

**See also:**

- `https://developer.android.com/reference/android/app/job/JobInfo.Builder#setRequiresDeviceIdle(boolean)`

Constant Value:

8
(0x00000008)


### PENDING_JOB_REASON_CONSTRAINT_MINIMUM_LATENCY

Added in [API level 34](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final int PENDING_JOB_REASON_CONSTRAINT_MINIMUM_LATENCY
```

The minimum latency has not transpired.

<br />

**See also:**

- `https://developer.android.com/reference/android/app/job/JobInfo.Builder#setMinimumLatency(long)`

Constant Value:

9
(0x00000009)


### PENDING_JOB_REASON_CONSTRAINT_PREFETCH

Added in [API level 34](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final int PENDING_JOB_REASON_CONSTRAINT_PREFETCH
```

The system's estimate of when the app will be launched is far away enough to warrant delaying
this job.

<br />

**See also:**

- `https://developer.android.com/reference/android/app/job/JobInfo#isPrefetch()`
- `https://developer.android.com/reference/android/app/job/JobInfo.Builder#setPrefetch(boolean)`

Constant Value:

10
(0x0000000a)


### PENDING_JOB_REASON_CONSTRAINT_STORAGE_NOT_LOW

Added in [API level 34](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final int PENDING_JOB_REASON_CONSTRAINT_STORAGE_NOT_LOW
```

The requested storage-not-low constraint is not satisfied.

<br />

**See also:**

- `https://developer.android.com/reference/android/app/job/JobInfo.Builder#setRequiresStorageNotLow(boolean)`

Constant Value:

11
(0x0000000b)


### PENDING_JOB_REASON_DEVICE_STATE

Added in [API level 34](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final int PENDING_JOB_REASON_DEVICE_STATE
```

The job is being deferred due to the device state (e.g., Doze, battery saver, memory usage,
thermal status, etc.).


Starting in a version of Android following
`https://developer.android.com/reference/android/os/Build.VERSION_CODES#CINNAMON_BUN`, the system will provide more specific
pending reasons when possible, such as `https://developer.android.com/` or
`https://developer.android.com/`

<br />

Constant Value:

12
(0x0000000c)


### PENDING_JOB_REASON_EXECUTING

Added in [API level 34](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final int PENDING_JOB_REASON_EXECUTING
```

The job is currently running and is therefore not pending.

<br />

Constant Value:

-1
(0xffffffff)


### PENDING_JOB_REASON_INVALID_JOB_ID

Added in [API level 34](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final int PENDING_JOB_REASON_INVALID_JOB_ID
```

The job doesn't exist.

<br />

Constant Value:

-2
(0xfffffffe)


### PENDING_JOB_REASON_JOB_SCHEDULER_OPTIMIZATION

Added in [API level 34](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final int PENDING_JOB_REASON_JOB_SCHEDULER_OPTIMIZATION
```

JobScheduler thinks it can defer this job to a more optimal running time.

<br />

Constant Value:

13
(0x0000000d)


### PENDING_JOB_REASON_QUOTA

Added in [API level 34](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final int PENDING_JOB_REASON_QUOTA
```

The app has consumed all of its current quota.

<br />

**See also:**

- `https://developer.android.com/reference/android/app/usage/UsageStatsManager#getAppStandbyBucket()`
- `https://developer.android.com/reference/android/app/job/JobParameters#STOP_REASON_QUOTA`

Constant Value:

14
(0x0000000e)


### PENDING_JOB_REASON_UNDEFINED

Added in [API level 34](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final int PENDING_JOB_REASON_UNDEFINED
```

There is no known reason why the job is pending.
If additional reasons are added on newer Android versions, the system may return this reason
to apps whose target SDK is not high enough to expect that reason.

<br />

Constant Value:

0
(0x00000000)


### PENDING_JOB_REASON_USER

Added in [API level 34](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final int PENDING_JOB_REASON_USER
```

JobScheduler is respecting one of the user's actions (eg. force stop or adb shell commands)
to defer this job.

<br />

Constant Value:

15
(0x0000000f)


### RESULT_FAILURE

Added in [API level 21](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final int RESULT_FAILURE
```

Returned from `https://developer.android.com/reference/android/app/job/JobScheduler#schedule(android.app.job.JobInfo)` if a job wasn't scheduled successfully. Scheduling
can fail for a variety of reasons, including, but not limited to:

- an invalid parameter was supplied (eg. the run-time for your job is too short, or the system can't resolve the requisite `https://developer.android.com/reference/android/app/job/JobService` in your package)
- 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.

<br />

<br />

Constant Value:

0
(0x00000000)


### RESULT_SUCCESS

Added in [API level 21](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final int RESULT_SUCCESS
```

Returned from `https://developer.android.com/reference/android/app/job/JobScheduler#schedule(android.app.job.JobInfo)` if this job has been successfully scheduled.

<br />

Constant Value:

1
(0x00000001)


## Public constructors

### JobScheduler

```
public JobScheduler ()
```

<br />

<br />

## Public methods

### canRunUserInitiatedJobs

Added in [API level 34](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public boolean canRunUserInitiatedJobs ()
```

Returns `true` if the calling app currently holds the
`https://developer.android.com/reference/android/Manifest.permission#RUN_USER_INITIATED_JOBS` permission, allowing it to run
user-initiated jobs.

<br />

| Returns ||
|---|---|
| `boolean` | <br /> |

### cancel

Added in [API level 21](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
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 `https://developer.android.com/reference/android/app/job/JobService#onStopJob(android.app.job.JobParameters)`
method is ignored.

<br />

| Parameters ||
|---|---|
| `jobId` | `int`: unique identifier for the job to be canceled, as supplied to `https://developer.android.com/reference/android/app/job/JobInfo.Builder#Builder(int,%20android.content.ComponentName)`. <br /> |

### cancelAll

Added in [API level 21](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public abstract void cancelAll ()
```

Cancel all jobs that have been scheduled in the current namespace by the
calling application.


Starting with Android version `https://developer.android.com/reference/android/os/Build.VERSION_CODES#UPSIDE_DOWN_CAKE`, this
will only cancel within the current namespace. If a namespace hasn't been explicitly set
with `https://developer.android.com/reference/android/app/job/JobScheduler#forNamespace(java.lang.String)`, then this will cancel jobs in the default namespace.
To cancel all jobs scheduled by the application,
use `https://developer.android.com/reference/android/app/job/JobScheduler#cancelInAllNamespaces()` instead.

<br />

### cancelInAllNamespaces

Added in [API level 34](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void cancelInAllNamespaces ()
```

Cancel *all* jobs that have been scheduled by the calling application, regardless of
namespace.

<br />

### enqueue

Added in [API level 26](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public abstract int enqueue (JobInfo job, 
                JobWorkItem work)
```

Similar to `https://developer.android.com/reference/android/app/job/JobScheduler#schedule(android.app.job.JobInfo)`, but allows you to enqueue work for a new *or existing*
job. If a job with the same ID is already scheduled, it will be replaced with the
new `https://developer.android.com/reference/android/app/job/JobInfo`, but any previously enqueued work will remain and be dispatched the
next time it runs. If a job with the same ID is already running, the new work will be
enqueued for it without stopping the job.

The work you enqueue is later retrieved through
`https://developer.android.com/reference/android/app/job/JobParameters#dequeueWork()`. Be sure to see there
about how to process work; the act of enqueueing work changes how you should handle the
overall lifecycle of an executing job.

It is strongly encouraged that you use the same `https://developer.android.com/reference/android/app/job/JobInfo` for all work you
enqueue. This will allow the system to optimally schedule work along with any pending
and/or currently running work. If the JobInfo changes from the last time the job was
enqueued, the system will need to update the associated JobInfo, which can cause a disruption
in execution. In particular, this can result in any currently running job that is processing
previous work to be stopped and restarted with the new JobInfo.

It is recommended that you avoid using
`https://developer.android.com/reference/android/app/job/JobInfo.Builder#setExtras(android.os.PersistableBundle)` or
`https://developer.android.com/reference/android/app/job/JobInfo.Builder#setTransientExtras(android.os.Bundle)` with a JobInfo you are using to
enqueue work. The system will try to compare these extras with the previous JobInfo,
but there are situations where it may get this wrong and count the JobInfo as changing.
(That said, you should be relatively safe with a simple set of consistent data in these
fields.) You should never use `https://developer.android.com/reference/android/app/job/JobInfo.Builder#setClipData(android.content.ClipData,%20int)` with
work you are enqueuing, since currently this will always be treated as a different JobInfo,
even if the ClipData contents are exactly the same.

**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 `https://developer.android.com/reference/android/os/Build.VERSION_CODES#Q`. As such, the system may throttle calls to
this API if calls are made too frequently in a short amount of time.

**Note:** Prior to Android version
`https://developer.android.com/reference/android/os/Build.VERSION_CODES#UPSIDE_DOWN_CAKE`, JobWorkItems could not be persisted.
Apps were not allowed to enqueue JobWorkItems with persisted jobs and the system would throw
an `https://developer.android.com/reference/java/lang/IllegalArgumentException` if they attempted to do so. Starting with
`https://developer.android.com/reference/android/os/Build.VERSION_CODES#UPSIDE_DOWN_CAKE`,
JobWorkItems can be persisted alongside the hosting job.
However, Intents cannot be persisted. Set a `https://developer.android.com/reference/android/os/PersistableBundle` using
`https://developer.android.com/reference/android/app/job/JobWorkItem.Builder#setExtras(android.os.PersistableBundle)` for any information that needs
to be persisted.

Note: The JobService component needs to be enabled in order to successfully schedule a
job.

<br />

| Parameters ||
|---|---|
| `job` | `JobInfo`: The job you wish to enqueue work for. See `https://developer.android.com/reference/android/app/job/JobInfo.Builder` for more detail on the sorts of jobs you can schedule. This value cannot be `null`. <br /> |
| `work` | `JobWorkItem`: New work to enqueue. This will be available later when the job starts running. This value cannot be `null`. <br /> |

| Returns ||
|---|---|
| `int` | the result of the enqueue request. Value is one of the following: - `https://developer.android.com/reference/android/app/job/JobScheduler#RESULT_FAILURE` - `https://developer.android.com/reference/android/app/job/JobScheduler#RESULT_SUCCESS` |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalArgumentException` | if the specified `https://developer.android.com/reference/android/app/job/JobService` doesn't exist or is disabled. |

### forNamespace

Added in [API level 34](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public JobScheduler forNamespace (String namespace)
```

Get a JobScheduler instance that is dedicated to a specific namespace. Any API calls using
this instance will interact with jobs in that namespace, unless the API documentation says
otherwise. Attempting to update a job scheduled in another namespace will not be possible
but will instead create or update the job inside the current namespace. A JobScheduler
instance dedicated to a namespace must be used to schedule or update jobs in that namespace.

Since leading and trailing whitespace can lead to hard-to-debug issues,
they will be `https://developer.android.com/reference/java/lang/String#trim()`. An empty String (after trimming) is not allowed.

<br />

| Parameters ||
|---|---|
| `namespace` | `String`: This value cannot be `null`. <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/app/job/JobScheduler` | This value cannot be `null`. <br /> |

**See also:**

- `https://developer.android.com/reference/android/app/job/JobScheduler#getNamespace()`

### getAllPendingJobs

Added in [API level 21](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public abstract List<JobInfo> getAllPendingJobs ()
```

Retrieve all jobs that have been scheduled by the calling application.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/util/List<https://developer.android.com/reference/android/app/job/JobInfo>` | 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`. <br /> |

### getNamespace

Added in [API level 34](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public String getNamespace ()
```

Get the namespace this JobScheduler instance is operating in. A `null` value means
that the app has not specified a namespace for this instance, and it is therefore using the
default namespace.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/lang/String` | <br /> |

### getPendingJob

Added in [API level 24](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public abstract JobInfo getPendingJob (int jobId)
```

Look up the description of a scheduled job.

<br />

| Parameters ||
|---|---|
| `jobId` | `int` <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/app/job/JobInfo` | The `https://developer.android.com/reference/android/app/job/JobInfo` description of the given scheduled job, or `null` if the supplied job ID does not correspond to any job. <br /> |

### getPendingJobReason

Added in [API level 34](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public int getPendingJobReason (int jobId)
```

Returns a reason why the job is pending and not currently executing. If there are multiple
reasons why a job may be pending, this will only return one of them.

<br />

##### API Note:

- To know all the potential reasons why the job may be pending, use `https://developer.android.com/reference/android/app/job/JobScheduler#getPendingJobReasons(int)` instead.

| Parameters ||
|---|---|
| `jobId` | `int` <br /> |

| Returns ||
|---|---|
| `int` | Value is one of the following: - `https://developer.android.com/reference/android/app/job/JobScheduler#PENDING_JOB_REASON_UNDEFINED` - `https://developer.android.com/reference/android/app/job/JobScheduler#PENDING_JOB_REASON_APP` - `https://developer.android.com/reference/android/app/job/JobScheduler#PENDING_JOB_REASON_APP_STANDBY` - `https://developer.android.com/reference/android/app/job/JobScheduler#PENDING_JOB_REASON_BACKGROUND_RESTRICTION` - `https://developer.android.com/reference/android/app/job/JobScheduler#PENDING_JOB_REASON_CONSTRAINT_BATTERY_NOT_LOW` - `https://developer.android.com/reference/android/app/job/JobScheduler#PENDING_JOB_REASON_CONSTRAINT_CHARGING` - `https://developer.android.com/reference/android/app/job/JobScheduler#PENDING_JOB_REASON_CONSTRAINT_CONNECTIVITY` - `https://developer.android.com/reference/android/app/job/JobScheduler#PENDING_JOB_REASON_CONSTRAINT_CONTENT_TRIGGER` - `https://developer.android.com/reference/android/app/job/JobScheduler#PENDING_JOB_REASON_CONSTRAINT_DEVICE_IDLE` - `https://developer.android.com/reference/android/app/job/JobScheduler#PENDING_JOB_REASON_CONSTRAINT_MINIMUM_LATENCY` - `https://developer.android.com/reference/android/app/job/JobScheduler#PENDING_JOB_REASON_CONSTRAINT_PREFETCH` - `https://developer.android.com/reference/android/app/job/JobScheduler#PENDING_JOB_REASON_CONSTRAINT_STORAGE_NOT_LOW` - `https://developer.android.com/reference/android/app/job/JobScheduler#PENDING_JOB_REASON_DEVICE_STATE` - `https://developer.android.com/reference/android/app/job/JobScheduler#PENDING_JOB_REASON_EXECUTING` - `https://developer.android.com/reference/android/app/job/JobScheduler#PENDING_JOB_REASON_INVALID_JOB_ID` - `https://developer.android.com/reference/android/app/job/JobScheduler#PENDING_JOB_REASON_JOB_SCHEDULER_OPTIMIZATION` - `https://developer.android.com/reference/android/app/job/JobScheduler#PENDING_JOB_REASON_QUOTA` - `https://developer.android.com/reference/android/app/job/JobScheduler#PENDING_JOB_REASON_USER` - `https://developer.android.com/reference/android/app/job/JobScheduler#PENDING_JOB_REASON_CONSTRAINT_DEADLINE` |

### getPendingJobReasonStats

Added in [API level 37](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public Map<Integer, Duration> getPendingJobReasonStats (int jobId)
```

For the given `jobId`, returns an aggregated view of why the job has been pending
execution over its lifetime. The returned map is composed of
`PENDING_JOB_REASON_*` constants mapped to a duration representing the total time
the job has been pending for that reason.


Note that the sum of these durations will often exceed the total duration the job was
waiting, since a job could be pending due to multiple reasons simultaneously.


These pending job reasons represent either explicitly set constraints on the job or implicit
constraints imposed by the system due to various reasons.
The results can be used to debug which constraints contribute the most to why a given job
has been pending execution.


If the returned map is empty, it could indicate that the job was executed immediately and
never had to wait for any constraints to be met.


To get a more detailed and historical view of why a job was pending at a certain time,
use `https://developer.android.com/reference/android/app/job/JobScheduler#getPendingJobReasonsHistory(int)` instead.


Note: The pending job reason stats are not persisted across device reboots. The stats are
also cleared when the job successfully completes or is canceled. Apps should query this
information when they observe a scheduled job is not executing as expected to understand
the reasons for the delay.

<br />

<br />

| Parameters ||
|---|---|
| `jobId` | `int`: The ID of the job to query. <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/util/Map<https://developer.android.com/reference/java/lang/Integer, https://developer.android.com/reference/java/time/Duration>` | A map of pending reasons to the total duration the job was pending for that reason. This value cannot be `null`. <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalArgumentException` | if the `jobId` does not correspond to a pending job. |

**See also:**

- `https://developer.android.com/reference/android/app/job/JobScheduler#getPendingJobReasons(int)`
- `https://developer.android.com/reference/android/app/job/JobScheduler#getPendingJobReasonsHistory(int)`

### getPendingJobReasons

Added in [API level 36](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public int[] getPendingJobReasons (int jobId)
```

Returns potential reasons why the job with the given `jobId` may be pending
and not currently executing.


The returned array will include reasons composed of both explicitly set constraints on the
job and implicit constraints imposed by the system.
The results can be used to debug why a given job may not be currently executing.

<br />

| Parameters ||
|---|---|
| `jobId` | `int` <br /> |

| Returns ||
|---|---|
| `int[]` | This value cannot be `null`. Value is one of the following: - `https://developer.android.com/reference/android/app/job/JobScheduler#PENDING_JOB_REASON_UNDEFINED` - `https://developer.android.com/reference/android/app/job/JobScheduler#PENDING_JOB_REASON_APP` - `https://developer.android.com/reference/android/app/job/JobScheduler#PENDING_JOB_REASON_APP_STANDBY` - `https://developer.android.com/reference/android/app/job/JobScheduler#PENDING_JOB_REASON_BACKGROUND_RESTRICTION` - `https://developer.android.com/reference/android/app/job/JobScheduler#PENDING_JOB_REASON_CONSTRAINT_BATTERY_NOT_LOW` - `https://developer.android.com/reference/android/app/job/JobScheduler#PENDING_JOB_REASON_CONSTRAINT_CHARGING` - `https://developer.android.com/reference/android/app/job/JobScheduler#PENDING_JOB_REASON_CONSTRAINT_CONNECTIVITY` - `https://developer.android.com/reference/android/app/job/JobScheduler#PENDING_JOB_REASON_CONSTRAINT_CONTENT_TRIGGER` - `https://developer.android.com/reference/android/app/job/JobScheduler#PENDING_JOB_REASON_CONSTRAINT_DEVICE_IDLE` - `https://developer.android.com/reference/android/app/job/JobScheduler#PENDING_JOB_REASON_CONSTRAINT_MINIMUM_LATENCY` - `https://developer.android.com/reference/android/app/job/JobScheduler#PENDING_JOB_REASON_CONSTRAINT_PREFETCH` - `https://developer.android.com/reference/android/app/job/JobScheduler#PENDING_JOB_REASON_CONSTRAINT_STORAGE_NOT_LOW` - `https://developer.android.com/reference/android/app/job/JobScheduler#PENDING_JOB_REASON_DEVICE_STATE` - `https://developer.android.com/reference/android/app/job/JobScheduler#PENDING_JOB_REASON_EXECUTING` - `https://developer.android.com/reference/android/app/job/JobScheduler#PENDING_JOB_REASON_INVALID_JOB_ID` - `https://developer.android.com/reference/android/app/job/JobScheduler#PENDING_JOB_REASON_JOB_SCHEDULER_OPTIMIZATION` - `https://developer.android.com/reference/android/app/job/JobScheduler#PENDING_JOB_REASON_QUOTA` - `https://developer.android.com/reference/android/app/job/JobScheduler#PENDING_JOB_REASON_USER` - `https://developer.android.com/reference/android/app/job/JobScheduler#PENDING_JOB_REASON_CONSTRAINT_DEADLINE` |

**See also:**

- `https://developer.android.com/reference/android/app/job/JobScheduler#getPendingJobReasonsHistory(int)`
- `https://developer.android.com/reference/android/app/job/JobScheduler#getPendingJobReasonStats(int)`

### getPendingJobReasonsHistory

Added in [API level 36](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public List<PendingJobReasonsInfo> getPendingJobReasonsHistory (int jobId)
```

For the given `jobId`, returns a limited historical view of why the job may have
been pending execution. The returned list is composed of `https://developer.android.com/reference/android/app/job/PendingJobReasonsInfo`
objects, each of which include a timestamp since epoch along with an array of
unsatisfied constraints represented by `PENDING_JOB_REASON_*` constants.


These constants could either be explicitly set constraints on the job or implicit
constraints imposed by the system due to various reasons.
The results can be used to debug why a given job may have been pending execution.


If `PENDING_JOB_REASON_UNDEFINED` is the only reason for the timestamp, it could mean
that the job was ready to be executed at that point in time.


The length of the history returned is truncated so it's recommended to query this API
periodically for debugging purposes. To get a holistic view of why the job has been pending,
use `https://developer.android.com/reference/android/app/job/JobScheduler#getPendingJobReasonStats(int)`.


Note: there is no set interval for the timestamps in the returned list since
constraint changes occur based on device status and various other factors.


Note: the pending job reasons history is not persisted across device reboots.

<br />

<br />

| Parameters ||
|---|---|
| `jobId` | `int` <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/util/List<https://developer.android.com/reference/android/app/job/PendingJobReasonsInfo>` | This value cannot be `null`. <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalArgumentException` | if the `jobId` is invalid. |

**See also:**

- `https://developer.android.com/reference/android/app/job/JobScheduler#getPendingJobReasons(int)`
- `https://developer.android.com/reference/android/app/job/JobScheduler#getPendingJobReasonStats(int)`

### getPendingJobsInAllNamespaces

Added in [API level 34](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public Map<String, List<JobInfo>> getPendingJobsInAllNamespaces ()
```

Retrieve all jobs that have been scheduled by the calling application within the current
namespace.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/util/Map<https://developer.android.com/reference/java/lang/String, https://developer.android.com/reference/java/util/List<https://developer.android.com/reference/android/app/job/JobInfo>>` | a list of all of the app's scheduled jobs scheduled with the current namespace. If a namespace hasn't been explicitly set with `https://developer.android.com/reference/android/app/job/JobScheduler#forNamespace(java.lang.String)`, then this will return jobs in the default namespace. This includes jobs that are currently started as well as those that are still waiting to run. This value cannot be `null`. <br /> |

### schedule

Added in [API level 21](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
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 `https://developer.android.com/reference/android/app/job/JobInfo`. If a job with the given ID is currently
running, it will be stopped.

**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 `https://developer.android.com/reference/android/os/Build.VERSION_CODES#Q`. As such, the system may throttle calls to
this API if calls are made too frequently in a short amount of time.

Note: The JobService component needs to be enabled in order to successfully schedule a
job.

<br />

| Parameters ||
|---|---|
| `job` | `JobInfo`: The job you wish scheduled. See `https://developer.android.com/reference/android/app/job/JobInfo.Builder` for more detail on the sorts of jobs you can schedule. This value cannot be `null`. <br /> |

| Returns ||
|---|---|
| `int` | the result of the schedule request. Value is one of the following: - `https://developer.android.com/reference/android/app/job/JobScheduler#RESULT_FAILURE` - `https://developer.android.com/reference/android/app/job/JobScheduler#RESULT_SUCCESS` |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalArgumentException` | if the specified `https://developer.android.com/reference/android/app/job/JobService` doesn't exist or is disabled. |