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/JobParameters#constants) \| [Inherited Constants](https://developer.android.com/reference/android/app/job/JobParameters#inhconstants) \| [Fields](https://developer.android.com/reference/android/app/job/JobParameters#lfields) \| [Methods](https://developer.android.com/reference/android/app/job/JobParameters#pubmethods) \| [Inherited Methods](https://developer.android.com/reference/android/app/job/JobParameters#inhmethods)

# JobParameters

*** ** * ** ***

` public class JobParameters `   
` extends https://developer.android.com/reference/java/lang/Object ` ` implements https://developer.android.com/reference/android/os/Parcelable `

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

<br />

*** ** * ** ***

Contains the parameters used to configure/identify your job. You do not create this object yourself, instead it is handed in to your application by the System.

## Summary

| ### Constants ||
|---|---|
| `int` | `https://developer.android.com/reference/android/app/job/JobParameters#STOP_REASON_APP_STANDBY` The current standby bucket requires that the job stop now. |
| `int` | `https://developer.android.com/reference/android/app/job/JobParameters#STOP_REASON_BACKGROUND_RESTRICTION` The app is restricted from running in the background. |
| `int` | `https://developer.android.com/reference/android/app/job/JobParameters#STOP_REASON_CANCELLED_BY_APP` The job was cancelled directly by the app, either by calling `https://developer.android.com/reference/android/app/job/JobScheduler#cancel(int)`, `https://developer.android.com/reference/android/app/job/JobScheduler#cancelAll()`, or by scheduling a new job with the same job ID. |
| `int` | `https://developer.android.com/reference/android/app/job/JobParameters#STOP_REASON_CONSTRAINT_BATTERY_NOT_LOW` The requested battery-not-low constraint is no longer satisfied. |
| `int` | `https://developer.android.com/reference/android/app/job/JobParameters#STOP_REASON_CONSTRAINT_CHARGING` The requested charging constraint is no longer satisfied. |
| `int` | `https://developer.android.com/reference/android/app/job/JobParameters#STOP_REASON_CONSTRAINT_CONNECTIVITY` The requested connectivity constraint is no longer satisfied. |
| `int` | `https://developer.android.com/reference/android/app/job/JobParameters#STOP_REASON_CONSTRAINT_DEVICE_IDLE` The requested idle constraint is no longer satisfied. |
| `int` | `https://developer.android.com/reference/android/app/job/JobParameters#STOP_REASON_CONSTRAINT_STORAGE_NOT_LOW` The requested storage-not-low constraint is no longer satisfied. |
| `int` | `https://developer.android.com/reference/android/app/job/JobParameters#STOP_REASON_DEVICE_STATE` The device state (e.g., Doze, battery saver, memory usage, etc.) requires JobScheduler to stop this job. |
| `int` | `https://developer.android.com/reference/android/app/job/JobParameters#STOP_REASON_ESTIMATED_APP_LAUNCH_TIME_CHANGED` The system's estimate of when the app will be launched changed significantly enough to decide this job shouldn't be running right now. |
| `int` | `https://developer.android.com/reference/android/app/job/JobParameters#STOP_REASON_PREEMPT` The job was stopped to run a higher priority job of the app. |
| `int` | `https://developer.android.com/reference/android/app/job/JobParameters#STOP_REASON_QUOTA` The app has consumed all of its current quota. |
| `int` | `https://developer.android.com/reference/android/app/job/JobParameters#STOP_REASON_SYSTEM_PROCESSING` The system is doing some processing that requires stopping this job. |
| `int` | `https://developer.android.com/reference/android/app/job/JobParameters#STOP_REASON_TIMEOUT` The job used up its maximum execution time and timed out. |
| `int` | `https://developer.android.com/reference/android/app/job/JobParameters#STOP_REASON_TIMEOUT_ABANDONED` The job used up its maximum execution time and timed out. |
| `int` | `https://developer.android.com/reference/android/app/job/JobParameters#STOP_REASON_UNDEFINED` There is no reason the job is stopped. |
| `int` | `https://developer.android.com/reference/android/app/job/JobParameters#STOP_REASON_USER` The user stopped the job. |

### Inherited constants

From interface `https://developer.android.com/reference/android/os/Parcelable` `int` `https://developer.android.com/reference/android/os/Parcelable#CONTENTS_FILE_DESCRIPTOR`

Descriptor bit used with `https://developer.android.com/reference/android/os/Parcelable#describeContents()`: indicates that the Parcelable object's flattened representation includes a file descriptor.
`int` `https://developer.android.com/reference/android/os/Parcelable#PARCELABLE_WRITE_RETURN_VALUE`

Flag for use with `https://developer.android.com/reference/android/os/Parcelable#writeToParcel(android.os.Parcel,%20int)`: the object being written is a return value, that is the result of a function such as "`Parcelable someFunction()`", "`void someFunction(out Parcelable)`", or "`void someFunction(inout Parcelable)`".

| ### Fields ||
|---|---|
| ` public static final https://developer.android.com/reference/android/os/Parcelable.Creator<https://developer.android.com/reference/android/app/job/JobParameters>` | `https://developer.android.com/reference/android/app/job/JobParameters#CREATOR` <br /> |

| ### Public methods ||
|---|---|
| ` void` | ` https://developer.android.com/reference/android/app/job/JobParameters#completeWork(android.app.job.JobWorkItem)(https://developer.android.com/reference/android/app/job/JobWorkItem work) ` Report the completion of executing a `https://developer.android.com/reference/android/app/job/JobWorkItem` previously returned by `https://developer.android.com/reference/android/app/job/JobParameters#dequeueWork()`. |
| ` https://developer.android.com/reference/android/app/job/JobWorkItem` | ` https://developer.android.com/reference/android/app/job/JobParameters#dequeueWork()() ` Dequeue the next pending `https://developer.android.com/reference/android/app/job/JobWorkItem` from these JobParameters associated with their currently running job. |
| ` int` | ` https://developer.android.com/reference/android/app/job/JobParameters#describeContents()() ` Describe the kinds of special objects contained in this Parcelable instance's marshaled representation. |
| ` https://developer.android.com/reference/android/content/ClipData` | ` https://developer.android.com/reference/android/app/job/JobParameters#getClipData()() ` |
| ` int` | ` https://developer.android.com/reference/android/app/job/JobParameters#getClipGrantFlags()() ` |
| ` https://developer.android.com/reference/android/os/PersistableBundle` | ` https://developer.android.com/reference/android/app/job/JobParameters#getExtras()() ` |
| ` int` | ` https://developer.android.com/reference/android/app/job/JobParameters#getJobId()() ` |
| ` https://developer.android.com/reference/java/lang/String` | ` https://developer.android.com/reference/android/app/job/JobParameters#getJobNamespace()() ` Get the namespace this job was placed in. |
| ` https://developer.android.com/reference/android/net/Network` | ` https://developer.android.com/reference/android/app/job/JobParameters#getNetwork()() ` Return the network that should be used to perform any network requests for this job. |
| ` int` | ` https://developer.android.com/reference/android/app/job/JobParameters#getStopReason()() ` Returns the reason `https://developer.android.com/reference/android/app/job/JobService#onStopJob(android.app.job.JobParameters)` was called on this job. |
| ` https://developer.android.com/reference/android/os/Bundle` | ` https://developer.android.com/reference/android/app/job/JobParameters#getTransientExtras()() ` |
| ` https://developer.android.com/reference/java/lang/String` | ` https://developer.android.com/reference/android/app/job/JobParameters#getTriggeredContentAuthorities()() ` For jobs with `https://developer.android.com/reference/android/app/job/JobInfo.Builder#addTriggerContentUri(android.app.job.JobInfo.TriggerContentUri)` set, this reports which content authorities have triggered the job. |
| ` https://developer.android.com/reference/android/net/Uri` | ` https://developer.android.com/reference/android/app/job/JobParameters#getTriggeredContentUris()() ` For jobs with `https://developer.android.com/reference/android/app/job/JobInfo.Builder#addTriggerContentUri(android.app.job.JobInfo.TriggerContentUri)` set, this reports which URIs have triggered the job. |
| ` boolean` | ` https://developer.android.com/reference/android/app/job/JobParameters#isExpeditedJob()() ` |
| ` boolean` | ` https://developer.android.com/reference/android/app/job/JobParameters#isOverrideDeadlineExpired()() ` For jobs with `https://developer.android.com/reference/android/app/job/JobInfo.Builder#setOverrideDeadline(long)` set, this provides an easy way to tell whether the job is being executed due to the deadline expiring. |
| ` boolean` | ` https://developer.android.com/reference/android/app/job/JobParameters#isUserInitiatedJob()() ` |
| ` void` | ` https://developer.android.com/reference/android/app/job/JobParameters#writeToParcel(android.os.Parcel,%20int)(https://developer.android.com/reference/android/os/Parcel dest, int flags) ` Flatten this object in to a Parcel. |

### 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*.
From interface ` https://developer.android.com/reference/android/os/Parcelable ` ` abstract int` ` https://developer.android.com/reference/android/os/Parcelable#describeContents()() `

Describe the kinds of special objects contained in this Parcelable instance's marshaled representation.
` abstract void` ` https://developer.android.com/reference/android/os/Parcelable#writeToParcel(android.os.Parcel,%20int)(https://developer.android.com/reference/android/os/Parcel dest, int flags) `

Flatten this object in to a Parcel.

## Constants

### STOP_REASON_APP_STANDBY

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

```
public static final int STOP_REASON_APP_STANDBY
```

The current standby bucket requires that the job stop now.

<br />

**See also:**

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

Constant Value: 12 (0x0000000c)

### STOP_REASON_BACKGROUND_RESTRICTION

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

```
public static final int STOP_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: 11 (0x0000000b)

### STOP_REASON_CANCELLED_BY_APP

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

```
public static final int STOP_REASON_CANCELLED_BY_APP
```

The job was cancelled directly by the app, either by calling `https://developer.android.com/reference/android/app/job/JobScheduler#cancel(int)`, `https://developer.android.com/reference/android/app/job/JobScheduler#cancelAll()`, or by scheduling a new job with the same job ID.

<br />

Constant Value: 1 (0x00000001)

### STOP_REASON_CONSTRAINT_BATTERY_NOT_LOW

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

```
public static final int STOP_REASON_CONSTRAINT_BATTERY_NOT_LOW
```

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

<br />

**See also:**

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

Constant Value: 5 (0x00000005)

### STOP_REASON_CONSTRAINT_CHARGING

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

```
public static final int STOP_REASON_CONSTRAINT_CHARGING
```

The requested charging constraint is no longer satisfied.

<br />

**See also:**

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

Constant Value: 6 (0x00000006)

### STOP_REASON_CONSTRAINT_CONNECTIVITY

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

```
public static final int STOP_REASON_CONSTRAINT_CONNECTIVITY
```

The requested connectivity constraint is no longer 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: 7 (0x00000007)

### STOP_REASON_CONSTRAINT_DEVICE_IDLE

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

```
public static final int STOP_REASON_CONSTRAINT_DEVICE_IDLE
```

The requested idle constraint is no longer satisfied.

<br />

**See also:**

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

Constant Value: 8 (0x00000008)

### STOP_REASON_CONSTRAINT_STORAGE_NOT_LOW

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

```
public static final int STOP_REASON_CONSTRAINT_STORAGE_NOT_LOW
```

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

<br />

**See also:**

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

Constant Value: 9 (0x00000009)

### STOP_REASON_DEVICE_STATE

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

```
public static final int STOP_REASON_DEVICE_STATE
```

The device state (e.g., Doze, battery saver, memory usage, etc.) requires JobScheduler to stop this job.

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 stop reasons when possible, such as `https://developer.android.com/` or `https://developer.android.com/`.

<br />

Constant Value: 4 (0x00000004)

### STOP_REASON_ESTIMATED_APP_LAUNCH_TIME_CHANGED

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

```
public static final int STOP_REASON_ESTIMATED_APP_LAUNCH_TIME_CHANGED
```

The system's estimate of when the app will be launched changed significantly enough to decide this job shouldn't be running right now. This will mostly apply to prefetch jobs.

<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: 15 (0x0000000f)

### STOP_REASON_PREEMPT

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

```
public static final int STOP_REASON_PREEMPT
```

The job was stopped to run a higher priority job of the app.

<br />

Constant Value: 2 (0x00000002)

### STOP_REASON_QUOTA

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

```
public static final int STOP_REASON_QUOTA
```

The app has consumed all of its current quota. Each app is assigned a quota of how much it can run jobs within a certain time frame. The quota is informed, in part, by app standby buckets. Once an app has used up all of its quota, it won't be able to start jobs until quota is replenished, is changed, or is temporarily not applied.

<br />

**See also:**

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

Constant Value: 10 (0x0000000a)

### STOP_REASON_SYSTEM_PROCESSING

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

```
public static final int STOP_REASON_SYSTEM_PROCESSING
```

The system is doing some processing that requires stopping this job.

<br />

Constant Value: 14 (0x0000000e)

### STOP_REASON_TIMEOUT

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

```
public static final int STOP_REASON_TIMEOUT
```

The job used up its maximum execution time and timed out. Each individual job has a maximum execution time limit, regardless of how much total quota the app has. See the note on `https://developer.android.com/reference/android/app/job/JobScheduler` and `https://developer.android.com/reference/android/app/job/JobInfo` for the execution time limits.

<br />

Constant Value: 3 (0x00000003)

### STOP_REASON_TIMEOUT_ABANDONED

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

```
public static final int STOP_REASON_TIMEOUT_ABANDONED
```

The job used up its maximum execution time and timed out. The system also detected that the app can no longer call `https://developer.android.com/reference/android/app/job/JobService#jobFinished(android.app.job.JobParameters,%20boolean)` for this job, likely because the strong reference to the job handle (`https://developer.android.com/reference/android/app/job/JobParameters`) passed to it via `https://developer.android.com/reference/android/app/job/JobService#onStartJob(android.app.job.JobParameters)` was lost. This can occur even if the app called `https://developer.android.com/reference/android/app/job/JobScheduler#cancel(int)`, `https://developer.android.com/reference/android/app/job/JobScheduler#cancelAll()`, or `https://developer.android.com/reference/android/app/job/JobScheduler#cancelInAllNamespaces()` to stop an active job while losing strong references to the job handle. In this case, the job is not necessarily abandoned. However, the system cannot distinguish such cases from truly abandoned jobs.

It is recommended that you use `https://developer.android.com/reference/android/app/job/JobService#jobFinished(android.app.job.JobParameters,%20boolean)` or return false from `https://developer.android.com/reference/android/app/job/JobService#onStartJob(android.app.job.JobParameters)` to stop an active job. This will prevent the occurrence of this stop reason and the need to handle it. The primary use case for this stop reason is to report a probable case of a job being abandoned.

<br />

<br />

Constant Value: 16 (0x00000010)

### STOP_REASON_UNDEFINED

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

```
public static final int STOP_REASON_UNDEFINED
```

There is no reason the job is stopped. This is the value returned from the JobParameters object passed to `https://developer.android.com/reference/android/app/job/JobService#onStartJob(android.app.job.JobParameters)`.

<br />

Constant Value: 0 (0x00000000)

### STOP_REASON_USER

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

```
public static final int STOP_REASON_USER
```

The user stopped the job. This can happen either through force-stop, adb shell commands, uninstalling, or some other UI.

<br />

Constant Value: 13 (0x0000000d)

## Fields

### CREATOR

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

```
public static final Creator<JobParameters> CREATOR
```

<br />

<br />

## Public methods

### completeWork

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

```
public void completeWork (JobWorkItem work)
```

Report the completion of executing a `https://developer.android.com/reference/android/app/job/JobWorkItem` previously returned by `https://developer.android.com/reference/android/app/job/JobParameters#dequeueWork()`. This tells the system you are done with the work associated with that item, so it will not be returned again. Note that if this is the last work in the queue, completing it here will *not* finish the overall job -- for that to happen, you still need to call `https://developer.android.com/reference/android/app/job/JobParameters#dequeueWork()` again.

If you are enqueueing work into a job, you must call this method for each piece of work you process. Do *not* call `https://developer.android.com/reference/android/app/job/JobService#jobFinished(android.app.job.JobParameters,%20boolean)` or else you can lose work in your queue.

<br />

<br />

| Parameters ||
|---|---|
| `work` | `JobWorkItem`: The work you have completed processing, as previously returned by `https://developer.android.com/reference/android/app/job/JobParameters#dequeueWork()` This value cannot be `null`. <br /> |

### dequeueWork

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

```
public JobWorkItem dequeueWork ()
```

Dequeue the next pending `https://developer.android.com/reference/android/app/job/JobWorkItem` from these JobParameters associated with their currently running job. Calling this method when there is no more work available and all previously dequeued work has been completed will result in the system taking care of stopping the job for you -- you should not call `https://developer.android.com/reference/android/app/job/JobService#jobFinished(android.app.job.JobParameters,%20boolean)` yourself (otherwise you risk losing an upcoming JobWorkItem that is being enqueued at the same time).

Once you are done with the `https://developer.android.com/reference/android/app/job/JobWorkItem` returned by this method, you must call `https://developer.android.com/reference/android/app/job/JobParameters#completeWork(android.app.job.JobWorkItem)` with it to inform the system that you are done executing the work. The job will not be finished until all dequeued work has been completed. You do not, however, have to complete each returned work item before dequeuing the next one -- you can use `https://developer.android.com/reference/android/app/job/JobParameters#dequeueWork()` multiple times before completing previous work if you want to process work in parallel, and you can complete the work in whatever order you want.

If the job runs to the end of its available time period before all work has been completed, it will stop as normal. You should return true from `https://developer.android.com/reference/android/app/job/JobService#onStopJob(android.app.job.JobParameters)` in order to have the job rescheduled, and by doing so any pending as well as remaining uncompleted work will be re-queued for the next time the job runs.

This example shows how to construct a JobService that will serially dequeue and process work that is available for it:

```
public class JobWorkService extends JobService {
    private NotificationManager mNM;
    private CommandProcessor mCurProcessor;

    /**
     * This is a task to dequeue and process work in the background.
     */
    final class CommandProcessor extends AsyncTask<Void, Void, Void> {
        private final JobParameters mParams;

        CommandProcessor(JobParameters params) {
            mParams = params;
        }

        @Override
        protected Void doInBackground(Void... params) {
            boolean cancelled;
            JobWorkItem work;

            /**
             * Iterate over available work.  Once dequeueWork() returns null, the
             * job's work queue is empty and the job has stopped, so we can let this
             * async task complete.
             */
            while (!(cancelled=isCancelled()) && (work=mParams.dequeueWork()) != null) {
                String txt = work.getIntent().getStringExtra("name");
                Log.i("JobWorkService", "Processing work: " + work + ", msg: " + txt);
                showNotification(txt);

                // Process work here...  we'll pretend by sleeping.
                try {
                    Thread.sleep(5000);
                } catch (InterruptedException e) {
                }

                hideNotification();

                // Tell system we have finished processing the work.
                Log.i("JobWorkService", "Done with: " + work);
                mParams.completeWork(work);
            }

            if (cancelled) {
                Log.i("JobWorkService", "CANCELLED!");
            }

            return null;
        }
    }

    @Override
    public void onCreate() {
        mNM = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
        Toast.makeText(this, R.string.service_created, Toast.LENGTH_SHORT).show();
    }

    @Override
    public void onDestroy() {
        hideNotification();
        Toast.makeText(this, R.string.service_destroyed, Toast.LENGTH_SHORT).show();
    }

    @Override
    public boolean onStartJob(JobParameters params) {
        // Start task to pull work out of the queue and process it.
        mCurProcessor = new CommandProcessor(params);
        mCurProcessor.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);

        // Allow the job to continue running while we process work.
        return true;
    }

    @Override
    public boolean onStopJob(JobParameters params) {
        // Have the processor cancel its current work.
        mCurProcessor.cancel(true);

        // Tell the system to reschedule the job -- the only reason we would be here is
        // because the job needs to stop for some reason before it has completed all of
        // its work, so we would like it to remain to finish that work in the future.
        return true;
    }

    /**
     * Show a notification while this service is running.
     */
    private void showNotification(String text) {
        // The PendingIntent to launch our activity if the user selects this notification
        PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
                new Intent(this, JobWorkServiceActivity.class), 0);

        // Set the info for the views that show in the notification panel.
        Notification.Builder noteBuilder = new Notification.Builder(this)
                .setSmallIcon(R.drawable.stat_sample)  // the status icon
                .setTicker(text)  // the status text
                .setWhen(System.currentTimeMillis())  // the time stamp
                .setContentTitle(getText(R.string.service_start_arguments_label))  // the label
                .setContentText(text)  // the contents of the entry
                .setContentIntent(contentIntent);  // The intent to send when the entry is clicked

        // We show this for as long as our service is processing a command.
        noteBuilder.setOngoing(true);

        // Send the notification.
        // We use a string id because it is a unique number.  We use it later to cancel.
        mNM.notify(R.string.job_service_created, noteBuilder.build());
    }

    private void hideNotification() {
        mNM.cancel(R.string.service_created);
    }
}
```

<br />

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/app/job/JobWorkItem` | Returns a new `https://developer.android.com/reference/android/app/job/JobWorkItem` if there is one pending, otherwise null. If null is returned, the system will also stop the job if all work has also been completed. (This means that for correct operation, you must always call dequeueWork() after you have completed other work, to check either for more work or allow the system to stop the job.) <br /> |

### describeContents

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

```
public int describeContents ()
```

Describe the kinds of special objects contained in this Parcelable instance's marshaled representation. For example, if the object will include a file descriptor in the output of `https://developer.android.com/reference/android/os/Parcelable#writeToParcel(android.os.Parcel,%20int)`, the return value of this method must include the `https://developer.android.com/reference/android/os/Parcelable#CONTENTS_FILE_DESCRIPTOR` bit.

<br />

| Returns ||
|---|---|
| `int` | a bitmask indicating the set of special object types marshaled by this Parcelable object instance. Value is either `0` or - `https://developer.android.com/reference/android/os/Parcelable#CONTENTS_FILE_DESCRIPTOR` |

### getClipData

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

```
public ClipData getClipData ()
```

<br />

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/content/ClipData` | The clip you passed in when constructing this job with `https://developer.android.com/reference/android/app/job/JobInfo.Builder#setClipData(android.content.ClipData,%20int)`. Will be null if it was not set. <br /> |

### getClipGrantFlags

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

```
public int getClipGrantFlags ()
```

<br />

<br />

| Returns ||
|---|---|
| `int` | The clip grant flags you passed in when constructing this job with `https://developer.android.com/reference/android/app/job/JobInfo.Builder#setClipData(android.content.ClipData,%20int)`. Will be 0 if it was not set. <br /> |

### getExtras

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

```
public PersistableBundle getExtras ()
```

<br />

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/os/PersistableBundle` | The extras you passed in when constructing this job with `https://developer.android.com/reference/android/app/job/JobInfo.Builder#setExtras(android.os.PersistableBundle)`. This will never be null. If you did not set any extras this will be an empty bundle. <br /> |

### getJobId

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

```
public int getJobId ()
```

<br />

<br />

| Returns ||
|---|---|
| `int` | The unique id of this job, specified at creation time. <br /> |

### getJobNamespace

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

```
public String getJobNamespace ()
```

Get the namespace this job was placed in.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/lang/String` | The namespace this job was scheduled in. Will be `null` if there was no explicit namespace set and this job is therefore in the default namespace. <br /> |

**See also:**

- `https://developer.android.com/reference/android/app/job/JobScheduler#forNamespace(java.lang.String)`

### getNetwork

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

```
public Network getNetwork ()
```

Return the network that should be used to perform any network requests for this job.

Devices may have multiple active network connections simultaneously, or they may not have a default network route at all. To correctly handle all situations like this, your job should always use the network returned by this method instead of implicitly using the default network route.

Note that the system may relax the constraints you originally requested, such as allowing a `https://developer.android.com/reference/android/app/job/JobInfo#NETWORK_TYPE_UNMETERED` job to run over a metered network when there is a surplus of metered data available. Starting in Android version `https://developer.android.com/reference/android/os/Build.VERSION_CODES#UPSIDE_DOWN_CAKE`, this will return `null` if the app does not hold the permissions specified in `https://developer.android.com/reference/android/app/job/JobInfo.Builder#setRequiredNetwork(android.net.NetworkRequest)`.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/net/Network` | the network that should be used to perform any network requests for this job, or `null` if this job didn't set any required network type or if the job executed when there was no available network to use. <br /> |

**See also:**

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

### getStopReason

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

```
public int getStopReason ()
```

Returns the reason `https://developer.android.com/reference/android/app/job/JobService#onStopJob(android.app.job.JobParameters)` was called on this job.

Apps should not rely on the stop reason for critical decision-making, as additional stop reasons may be added in subsequent Android releases. The primary intended use of this method is for logging and diagnostic purposes to gain insights into the causes of job termination.

<br />

<br />

| Returns ||
|---|---|
| `int` | The reason `https://developer.android.com/reference/android/app/job/JobService#onStopJob(android.app.job.JobParameters)` was called on this job. Will be `https://developer.android.com/reference/android/app/job/JobParameters#STOP_REASON_UNDEFINED` if `https://developer.android.com/reference/android/app/job/JobService#onStopJob(android.app.job.JobParameters)` has not yet been called. Value is one of the following: - `https://developer.android.com/reference/android/app/job/JobParameters#STOP_REASON_UNDEFINED` - `https://developer.android.com/reference/android/app/job/JobParameters#STOP_REASON_CANCELLED_BY_APP` - `https://developer.android.com/reference/android/app/job/JobParameters#STOP_REASON_PREEMPT` - `https://developer.android.com/reference/android/app/job/JobParameters#STOP_REASON_TIMEOUT` - `https://developer.android.com/reference/android/app/job/JobParameters#STOP_REASON_DEVICE_STATE` - `https://developer.android.com/reference/android/app/job/JobParameters#STOP_REASON_CONSTRAINT_BATTERY_NOT_LOW` - `https://developer.android.com/reference/android/app/job/JobParameters#STOP_REASON_CONSTRAINT_CHARGING` - `https://developer.android.com/reference/android/app/job/JobParameters#STOP_REASON_CONSTRAINT_CONNECTIVITY` - `https://developer.android.com/reference/android/app/job/JobParameters#STOP_REASON_CONSTRAINT_DEVICE_IDLE` - `https://developer.android.com/reference/android/app/job/JobParameters#STOP_REASON_CONSTRAINT_STORAGE_NOT_LOW` - `https://developer.android.com/reference/android/app/job/JobParameters#STOP_REASON_QUOTA` - `https://developer.android.com/reference/android/app/job/JobParameters#STOP_REASON_BACKGROUND_RESTRICTION` - `https://developer.android.com/reference/android/app/job/JobParameters#STOP_REASON_APP_STANDBY` - `https://developer.android.com/reference/android/app/job/JobParameters#STOP_REASON_USER` - `https://developer.android.com/reference/android/app/job/JobParameters#STOP_REASON_SYSTEM_PROCESSING` - `https://developer.android.com/reference/android/app/job/JobParameters#STOP_REASON_ESTIMATED_APP_LAUNCH_TIME_CHANGED` - `https://developer.android.com/reference/android/app/job/JobParameters#STOP_REASON_TIMEOUT_ABANDONED` |

### getTransientExtras

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

```
public Bundle getTransientExtras ()
```

<br />

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/os/Bundle` | The transient extras you passed in when constructing this job with `https://developer.android.com/reference/android/app/job/JobInfo.Builder#setTransientExtras(android.os.Bundle)`. This will never be null. If you did not set any extras this will be an empty bundle. <br /> |

### getTriggeredContentAuthorities

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

```
public String[] getTriggeredContentAuthorities ()
```

For jobs with `https://developer.android.com/reference/android/app/job/JobInfo.Builder#addTriggerContentUri(android.app.job.JobInfo.TriggerContentUri)` set, this reports which content authorities have triggered the job. It will only be null if no authorities have triggered it -- that is, the job executed for some other reason, such as a deadline expiring. If this is non-null, you can use `https://developer.android.com/reference/android/app/job/JobParameters#getTriggeredContentUris()` to retrieve the details of which URIs changed (as long as that has not exceeded the maximum number it can reported).

<br />

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

### getTriggeredContentUris

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

```
public Uri[] getTriggeredContentUris ()
```

For jobs with `https://developer.android.com/reference/android/app/job/JobInfo.Builder#addTriggerContentUri(android.app.job.JobInfo.TriggerContentUri)` set, this reports which URIs have triggered the job. This will be null if either no URIs have triggered it (it went off due to a deadline or other reason), or the number of changed URIs is too large to report. Whether or not the number of URIs is too large, you can always use `https://developer.android.com/reference/android/app/job/JobParameters#getTriggeredContentAuthorities()` to determine whether the job was triggered due to any content changes and the authorities they are associated with.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/net/Uri` | <br /> |

### isExpeditedJob

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

```
public boolean isExpeditedJob ()
```

<br />

<br />

| Returns ||
|---|---|
| `boolean` | Whether this job is running as an expedited job or not. A job is guaranteed to have all expedited job guarantees for the duration of the job execution if this returns `true`. This will return `false` if the job that wasn't requested to run as a expedited job, or if it was requested to run as an expedited job but the app didn't have any remaining expedited job quota at the time of execution. <br /> |

**See also:**

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

### isOverrideDeadlineExpired

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

```
public boolean isOverrideDeadlineExpired ()
```

For jobs with `https://developer.android.com/reference/android/app/job/JobInfo.Builder#setOverrideDeadline(long)` set, this provides an easy way to tell whether the job is being executed due to the deadline expiring. Note: If the job is running because its deadline expired, it implies that its constraints will not be met. However, `https://developer.android.com/reference/android/app/job/JobInfo.Builder#setPeriodic(long)` will only ever run when their constraints are satisfied, therefore, the constraints will still be satisfied for a periodic job even if the deadline has expired.

<br />

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

### isUserInitiatedJob

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

```
public boolean isUserInitiatedJob ()
```

<br />

<br />

| Returns ||
|---|---|
| `boolean` | Whether this job is running as a user-initiated job or not. A job is guaranteed to have all user-initiated job guarantees for the duration of the job execution if this returns `true`. This will return `false` if the job wasn't requested to run as a user-initiated job, or if it was requested to run as a user-initiated job but the app didn't meet any of the requirements at the time of execution, such as having the `https://developer.android.com/reference/android/Manifest.permission#RUN_USER_INITIATED_JOBS` permission. <br /> |

**See also:**

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

### writeToParcel

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

```
public void writeToParcel (Parcel dest, 
                int flags)
```

Flatten this object in to a Parcel.

<br />

| Parameters ||
|---|---|
| `dest` | `Parcel`: The Parcel in which the object should be written. This value cannot be `null`. <br /> |
| `flags` | `int`: Additional flags about how the object should be written. May be 0 or `https://developer.android.com/reference/android/os/Parcelable#PARCELABLE_WRITE_RETURN_VALUE`. Value is either `0` or a combination of the following: - `https://developer.android.com/reference/android/os/Parcelable#PARCELABLE_WRITE_RETURN_VALUE` |