JobInfo


public class JobInfo
extends Object implements Parcelable

java.lang.Object
   ↳ android.app.job.JobInfo


Container of data passed to the JobScheduler fully encapsulating the parameters required to schedule work against the calling application. These are constructed using the JobInfo.Builder. The goal here is to provide the scheduler with high-level semantics about the work you want to accomplish.

Prior to Android version Build.VERSION_CODES.Q, you had to specify at least one constraint on the JobInfo object that you are creating. Otherwise, the builder would throw an exception when building. From Android version Build.VERSION_CODES.Q and onwards, it is valid to schedule jobs with no constraints.

Summary

Nested classes

class JobInfo.Builder

Builder class for constructing JobInfo objects. 

class JobInfo.TriggerContentUri

Information about a content URI modification that a job would like to trigger on. 

Constants

int BACKOFF_POLICY_EXPONENTIAL

Exponentially back-off a failed job.

int BACKOFF_POLICY_LINEAR

Linearly back-off a failed job.

long DEFAULT_INITIAL_BACKOFF_MILLIS

Amount of backoff a job has initially by default, in milliseconds.

long MAX_BACKOFF_DELAY_MILLIS

Maximum backoff we allow for a job, in milliseconds.

int NETWORK_BYTES_UNKNOWN

Sentinel value indicating that bytes are unknown.

int NETWORK_TYPE_ANY

This job requires network connectivity.

int NETWORK_TYPE_CELLULAR

This job requires network connectivity that is a cellular network.

int NETWORK_TYPE_METERED

This constant was deprecated in API level 28. Cellular networks may be unmetered, or Wi-Fi networks may be metered, so this isn't a good way of selecting a specific transport. Instead, use NETWORK_TYPE_CELLULAR or NetworkRequest.Builder.addTransportType(int) if your job requires a specific network transport.

int NETWORK_TYPE_NONE

Default.

int NETWORK_TYPE_NOT_ROAMING

This job requires network connectivity that is not roaming.

int NETWORK_TYPE_UNMETERED

This job requires network connectivity that is unmetered.

int PRIORITY_DEFAULT

Default value for all regular jobs.

int PRIORITY_HIGH

This task should be ordered ahead of most other tasks.

int PRIORITY_LOW

Low priority.

int PRIORITY_MAX

This task is critical to user experience or functionality and should be run ahead of all other tasks.

int PRIORITY_MIN

Job has minimal value to the user.

Inherited constants

Fields

public static final Creator<JobInfo> CREATOR

Public methods

int describeContents()

Describe the kinds of special objects contained in this Parcelable instance's marshaled representation.

boolean equals(Object o)

Indicates whether some other object is "equal to" this one.

int getBackoffPolicy()

Return the backoff policy of this job.

ClipData getClipData()
int getClipGrantFlags()
Set<String> getDebugTags()
long getEstimatedNetworkDownloadBytes()

Return the estimated size of download traffic that will be performed by this job, in bytes.

long getEstimatedNetworkUploadBytes()

Return the estimated size of upload traffic that will be performed by this job, in bytes.

PersistableBundle getExtras()
long getFlexMillis()

Flex time for this job.

int getId()

Unique job id associated with this application (uid).

long getInitialBackoffMillis()

The amount of time the JobScheduler will wait before rescheduling a failed job.

long getIntervalMillis()

Set to the interval between occurrences of this job.

long getMaxExecutionDelayMillis()
static final long getMinFlexMillis()

Query the minimum flex time allowed for periodic scheduled jobs.

long getMinLatencyMillis()

Set for a job that does not recur periodically, to specify a delay after which the job will be eligible for execution.

static final long getMinPeriodMillis()

Query the minimum interval allowed for periodic scheduled jobs.

long getMinimumNetworkChunkBytes()

Return the smallest piece of data that cannot be easily paused and resumed, in bytes.

int getNetworkType()

This method was deprecated in API level 28. This method attempts to map getRequiredNetwork() into the set of simple constants, which results in a loss of fidelity. Callers should move to using getRequiredNetwork() directly.

int getPriority()
NetworkRequest getRequiredNetwork()

Return the detailed description of the kind of network this job requires, or null if no specific kind of network is required.

ComponentName getService()

Name of the service endpoint that will be called back into by the JobScheduler.

String getTraceTag()
Bundle getTransientExtras()
long getTriggerContentMaxDelay()

When triggering on content URI changes, this is the maximum delay we will use before scheduling the job.

long getTriggerContentUpdateDelay()

When triggering on content URI changes, this is the delay from when a change is detected until the job is scheduled.

TriggerContentUri[] getTriggerContentUris()

Which content: URIs must change for the job to be scheduled.

int hashCode()

Returns a hash code value for the object.

boolean isExpedited()
boolean isImportantWhileForeground()

This method was deprecated in API level Baklava. Use isExpedited() instead.

boolean isPeriodic()

Track whether this job will repeat with a given period.

boolean isPersisted()
boolean isPrefetch()
boolean isRequireBatteryNotLow()
boolean isRequireCharging()
boolean isRequireDeviceIdle()
boolean isRequireStorageNotLow()
boolean isUserInitiated()
String toString()

Returns a string representation of the object.

void writeToParcel(Parcel out, int flags)

Flatten this object in to a Parcel.

Inherited methods

Constants

BACKOFF_POLICY_EXPONENTIAL

Added in API level 21
public static final int BACKOFF_POLICY_EXPONENTIAL

Exponentially back-off a failed job. See JobInfo.Builder.setBackoffCriteria(long, int) retry_time(current_time, num_failures) = current_time + initial_backoff_millis * 2 ^ (num_failures - 1), num_failures >= 1

Constant Value: 1 (0x00000001)

BACKOFF_POLICY_LINEAR

Added in API level 21
public static final int BACKOFF_POLICY_LINEAR

Linearly back-off a failed job. See JobInfo.Builder.setBackoffCriteria(long, int) retry_time(current_time, num_failures) = current_time + initial_backoff_millis * num_failures, num_failures >= 1

Constant Value: 0 (0x00000000)

DEFAULT_INITIAL_BACKOFF_MILLIS

Added in API level 21
public static final long DEFAULT_INITIAL_BACKOFF_MILLIS

Amount of backoff a job has initially by default, in milliseconds.

Constant Value: 30000 (0x0000000000007530)

MAX_BACKOFF_DELAY_MILLIS

Added in API level 21
public static final long MAX_BACKOFF_DELAY_MILLIS

Maximum backoff we allow for a job, in milliseconds.

Constant Value: 18000000 (0x000000000112a880)

NETWORK_BYTES_UNKNOWN

Added in API level 28
public static final int NETWORK_BYTES_UNKNOWN

Sentinel value indicating that bytes are unknown.

Constant Value: -1 (0xffffffff)

NETWORK_TYPE_ANY

Added in API level 21
public static final int NETWORK_TYPE_ANY

This job requires network connectivity.

Constant Value: 1 (0x00000001)

NETWORK_TYPE_CELLULAR

Added in API level 28
public static final int NETWORK_TYPE_CELLULAR

This job requires network connectivity that is a cellular network.

Constant Value: 4 (0x00000004)

NETWORK_TYPE_METERED

Added in API level 26
Deprecated in API level 28
public static final int NETWORK_TYPE_METERED

This constant was deprecated in API level 28.
Cellular networks may be unmetered, or Wi-Fi networks may be metered, so this isn't a good way of selecting a specific transport. Instead, use NETWORK_TYPE_CELLULAR or NetworkRequest.Builder.addTransportType(int) if your job requires a specific network transport.

This job requires metered connectivity such as most cellular data networks.

Constant Value: 4 (0x00000004)

NETWORK_TYPE_NONE

Added in API level 21
public static final int NETWORK_TYPE_NONE

Default.

Constant Value: 0 (0x00000000)

NETWORK_TYPE_NOT_ROAMING

Added in API level 24
public static final int NETWORK_TYPE_NOT_ROAMING

This job requires network connectivity that is not roaming.

Constant Value: 3 (0x00000003)

NETWORK_TYPE_UNMETERED

Added in API level 21
public static final int NETWORK_TYPE_UNMETERED

This job requires network connectivity that is unmetered.

Constant Value: 2 (0x00000002)

PRIORITY_DEFAULT

Added in API level 33
public static final int PRIORITY_DEFAULT

Default value for all regular jobs. As noted in JobScheduler, these jobs have a general execution time of 10 minutes. Receives the standard job management policy.

Constant Value: 300 (0x0000012c)

PRIORITY_HIGH

Added in API level 33
public static final int PRIORITY_HIGH

This task should be ordered ahead of most other tasks. It may be deferred a little, but if it doesn't run at some point, the user may think something is wrong. Assuming all constraints remain satisfied (including ideal system load conditions), these jobs can have an execution time of at least 4 minutes. Setting all of your jobs to high priority will not be beneficial to your app and in fact may hurt its performance in the long run.

Constant Value: 400 (0x00000190)

PRIORITY_LOW

Added in API level 33
public static final int PRIORITY_LOW

Low priority. The task provides some benefit to users, but is not critical and is more of a nice-to-have. This is more important than minimum priority jobs and will be prioritized ahead of them, but may still be deferred in lieu of higher priority jobs. JobScheduler may decide to defer these tasks while there are higher priority tasks in order to ensure there is sufficient quota available for the higher priority tasks. A sample task of low priority: prefetching data the user hasn't requested

Constant Value: 200 (0x000000c8)

PRIORITY_MAX

Added in API level 33
public static final int PRIORITY_MAX

This task is critical to user experience or functionality and should be run ahead of all other tasks. Only expedited jobs and user-initiated jobs can have this priority.

Example tasks of max priority:

  • Receiving a text message and processing it to show a notification
  • Downloading or uploading some content the user requested to transfer immediately

Constant Value: 500 (0x000001f4)

PRIORITY_MIN

Added in API level 33
public static final int PRIORITY_MIN

Job has minimal value to the user. The user has absolutely no expectation or knowledge of this task and it has no bearing on the user's perception of the app whatsoever. JobScheduler may decide to defer these tasks while there are higher priority tasks in order to ensure there is sufficient quota available for the higher priority tasks. A sample task of min priority: uploading analytics

Constant Value: 100 (0x00000064)

Fields

CREATOR

Added in API level 21
public static final Creator<JobInfo> CREATOR

Public methods

describeContents

Added in API level 21
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 writeToParcel(android.os.Parcel, int), the return value of this method must include the CONTENTS_FILE_DESCRIPTOR bit.

Returns
int a bitmask indicating the set of special object types marshaled by this Parcelable object instance. Value is either 0 or CONTENTS_FILE_DESCRIPTOR

equals

Added in API level 21
public boolean equals (Object o)

Indicates whether some other object is "equal to" this one.

The equals method implements an equivalence relation on non-null object references:

  • It is reflexive: for any non-null reference value x, x.equals(x) should return true.
  • It is symmetric: for any non-null reference values x and y, x.equals(y) should return true if and only if y.equals(x) returns true.
  • It is transitive: for any non-null reference values x, y, and z, if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.
  • It is consistent: for any non-null reference values x and y, multiple invocations of x.equals(y) consistently return true or consistently return false, provided no information used in equals comparisons on the objects is modified.
  • For any non-null reference value x, x.equals(null) should return false.

An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes.

Parameters
o Object: the reference object with which to compare.

Returns
boolean true if this object is the same as the obj argument; false otherwise.

getBackoffPolicy

Added in API level 21
public int getBackoffPolicy ()

Return the backoff policy of this job.

Returns
int Value is BACKOFF_POLICY_LINEAR, or BACKOFF_POLICY_EXPONENTIAL

getClipData

Added in API level 26
public ClipData getClipData ()

Returns
ClipData This value may be null.

getClipGrantFlags

Added in API level 26
public int getClipGrantFlags ()

Returns
int

getDebugTags

Added in API level 35
public Set<String> getDebugTags ()

Returns
Set<String> This value cannot be null.

getEstimatedNetworkDownloadBytes

Added in API level 28
public long getEstimatedNetworkDownloadBytes ()

Return the estimated size of download traffic that will be performed by this job, in bytes.
Value is a non-negative number of bytes.

Returns
long Estimated size of download traffic, or NETWORK_BYTES_UNKNOWN when unknown. Value is a non-negative number of bytes.

getEstimatedNetworkUploadBytes

Added in API level 28
public long getEstimatedNetworkUploadBytes ()

Return the estimated size of upload traffic that will be performed by this job, in bytes.
Value is a non-negative number of bytes.

Returns
long Estimated size of upload traffic, or NETWORK_BYTES_UNKNOWN when unknown. Value is a non-negative number of bytes.

getExtras

Added in API level 21
public PersistableBundle getExtras ()

Returns
PersistableBundle This value cannot be null.

getFlexMillis

Added in API level 24
public long getFlexMillis ()

Flex time for this job. Only valid if this is a periodic job. The job can execute at any time in a window of flex length at the end of the period.

Returns
long

getId

Added in API level 21
public int getId ()

Unique job id associated with this application (uid). This is the same job ID you supplied in the Builder constructor.

Returns
int

getInitialBackoffMillis

Added in API level 21
public long getInitialBackoffMillis ()

The amount of time the JobScheduler will wait before rescheduling a failed job. This value will be increased depending on the backoff policy specified at job creation time. Defaults to 30 seconds, minimum is currently 10 seconds.

Returns
long

getIntervalMillis

Added in API level 21
public long getIntervalMillis ()

Set to the interval between occurrences of this job. This value is not set if the job does not recur periodically.

Returns
long

getMaxExecutionDelayMillis

Added in API level 21
public long getMaxExecutionDelayMillis ()

Returns
long

getMinFlexMillis

Added in API level 24
public static final long getMinFlexMillis ()

Query the minimum flex time allowed for periodic scheduled jobs. Attempting to declare a shorter flex time than this when scheduling such a job will result in this amount as the effective flex time for the job.

Returns
long The minimum available flex time for scheduling periodic jobs, in milliseconds.

getMinLatencyMillis

Added in API level 21
public long getMinLatencyMillis ()

Set for a job that does not recur periodically, to specify a delay after which the job will be eligible for execution. This value is not set if the job recurs periodically.

Returns
long

getMinPeriodMillis

Added in API level 24
public static final long getMinPeriodMillis ()

Query the minimum interval allowed for periodic scheduled jobs. Attempting to declare a smaller period than this when scheduling a job will result in a job that is still periodic, but will run with this effective period.

Returns
long The minimum available interval for scheduling periodic jobs, in milliseconds.

getMinimumNetworkChunkBytes

Added in API level 33
public long getMinimumNetworkChunkBytes ()

Return the smallest piece of data that cannot be easily paused and resumed, in bytes.
Value is a non-negative number of bytes.

Returns
long Smallest piece of data that cannot be easily paused and resumed, or NETWORK_BYTES_UNKNOWN when unknown. Value is a non-negative number of bytes.

getNetworkType

Added in API level 21
Deprecated in API level 28
public int getNetworkType ()

This method was deprecated in API level 28.
This method attempts to map getRequiredNetwork() into the set of simple constants, which results in a loss of fidelity. Callers should move to using getRequiredNetwork() directly.

Return the basic description of the kind of network this job requires.

Returns
int Value is NETWORK_TYPE_NONE, NETWORK_TYPE_ANY, NETWORK_TYPE_UNMETERED, NETWORK_TYPE_NOT_ROAMING, or NETWORK_TYPE_CELLULAR

getPriority

Added in API level 33
public int getPriority ()

Returns
int Value is PRIORITY_MIN, PRIORITY_LOW, PRIORITY_DEFAULT, PRIORITY_HIGH, or PRIORITY_MAX

getRequiredNetwork

Added in API level 28
public NetworkRequest getRequiredNetwork ()

Return the detailed description of the kind of network this job requires, or null if no specific kind of network is required.

Returns
NetworkRequest

getService

Added in API level 21
public ComponentName getService ()

Name of the service endpoint that will be called back into by the JobScheduler.

Returns
ComponentName This value cannot be null.

getTraceTag

Added in API level 35
public String getTraceTag ()

Returns
String This value may be null.

getTransientExtras

Added in API level 26
public Bundle getTransientExtras ()

Returns
Bundle This value cannot be null.

getTriggerContentMaxDelay

Added in API level 24
public long getTriggerContentMaxDelay ()

When triggering on content URI changes, this is the maximum delay we will use before scheduling the job.

Returns
long

getTriggerContentUpdateDelay

Added in API level 24
public long getTriggerContentUpdateDelay ()

When triggering on content URI changes, this is the delay from when a change is detected until the job is scheduled.

Returns
long

getTriggerContentUris

Added in API level 24
public TriggerContentUri[] getTriggerContentUris ()

Which content: URIs must change for the job to be scheduled. Returns null if there are none required.

Returns
TriggerContentUri[]

hashCode

Added in API level 21
public int hashCode ()

Returns a hash code value for the object. This method is supported for the benefit of hash tables such as those provided by HashMap.

The general contract of hashCode is:

  • Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
  • If two objects are equal according to the equals method, then calling the hashCode method on each of the two objects must produce the same integer result.
  • It is not required that if two objects are unequal according to the equals method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.

Returns
int a hash code value for this object.

isExpedited

Added in API level 31
public boolean isExpedited ()

Returns
boolean

isImportantWhileForeground

Added in API level 28
Deprecated in API level Baklava
public boolean isImportantWhileForeground ()

This method was deprecated in API level Baklava.
Use isExpedited() instead.

Note: Beginning with ERROR(/android.os.Build.VERSION_CODES#B), this flag will be ignored and no longer function effectively, regardless of the calling app's target SDK version. Calling this method will always return false.

Returns
boolean

isPeriodic

Added in API level 21
public boolean isPeriodic ()

Track whether this job will repeat with a given period.

Returns
boolean

isPersisted

Added in API level 21
public boolean isPersisted ()

Returns
boolean

isPrefetch

Added in API level 28
public boolean isPrefetch ()

Returns
boolean

isRequireBatteryNotLow

Added in API level 26
public boolean isRequireBatteryNotLow ()

Returns
boolean

isRequireCharging

Added in API level 21
public boolean isRequireCharging ()

Returns
boolean

isRequireDeviceIdle

Added in API level 21
public boolean isRequireDeviceIdle ()

Returns
boolean

isRequireStorageNotLow

Added in API level 26
public boolean isRequireStorageNotLow ()

Returns
boolean

isUserInitiated

Added in API level 34
public boolean isUserInitiated ()

Returns
boolean

toString

Added in API level 21
public String toString ()

Returns a string representation of the object.

Returns
String a string representation of the object.

writeToParcel

Added in API level 21
public void writeToParcel (Parcel out, 
                int flags)

Flatten this object in to a Parcel.

Parameters
out Parcel: The Parcel in which the object should be written. This value cannot be null.

flags int: Additional flags about how the object should be written. May be 0 or Parcelable.PARCELABLE_WRITE_RETURN_VALUE. Value is either 0 or a combination of Parcelable.PARCELABLE_WRITE_RETURN_VALUE, and android.os.Parcelable.PARCELABLE_ELIDE_DUPLICATES