lightbulb_outline Help shape the future of the Google Play Console, Android Studio, and Firebase. Start survey

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. You must specify at least one sort of constraint on the JobInfo object that you are creating. The goal here is to provide the scheduler with high-level semantics about the work you want to accomplish. Doing otherwise with throw an exception in your app.

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.

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()
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.

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.

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.

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 isImportantWhileForeground()
boolean isPeriodic()

Track whether this job will repeat with a given period.

boolean isPersisted()
boolean isPrefetch()
boolean isRequireBatteryNotLow()
boolean isRequireCharging()
boolean isRequireDeviceIdle()
boolean isRequireStorageNotLow()
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
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)

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(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.

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.

The equals method for class Object implements the most discriminating possible equivalence relation on objects; that is, for any non-null reference values x and y, this method returns true if and only if x and y refer to the same object (x == y has the value true).

Note that it is generally necessary to override the hashCode method whenever this method is overridden, so as to maintain the general contract for the hashCode method, which states that equal objects must have equal hash codes.

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

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 will never 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 JobInfo.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 that 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.

getNetworkType

added in API level 21
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_METERED.

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

This value may be null.

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 will never be null.

getTransientExtras

added in API level 26
public Bundle getTransientExtras ()

Returns
Bundle

This value will never 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[]

This value may be null.

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(Object) 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(java.lang.Object) 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.

As much as is reasonably practical, the hashCode method defined by class Object does return distinct integers for distinct objects. (This is typically implemented by converting the internal address of the object into an integer, but this implementation technique is not required by the Java™ programming language.)

Returns
int a hash code value for this object.

isImportantWhileForeground

added in API level 28
public boolean isImportantWhileForeground ()

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

toString

added in API level 21
public String toString ()

Returns a string representation of the object. In general, the toString method returns a string that "textually represents" this object. The result should be a concise but informative representation that is easy for a person to read. It is recommended that all subclasses override this method.

The toString method for class Object returns a string consisting of the name of the class of which the object is an instance, the at-sign character `@', and the unsigned hexadecimal representation of the hash code of the object. In other words, this method returns a string equal to the value of:

 getClass().getName() + '@' + Integer.toHexString(hashCode())
 

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.

flags int: Additional flags about how the object should be written. May be 0 or Parcelable.PARCELABLE_WRITE_RETURN_VALUE.