Sdílet prostřednictvím


JobScheduler Class

Definition

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

[Android.Runtime.Register("android/app/job/JobScheduler", DoNotGenerateAcw=true)]
public abstract class JobScheduler : Java.Lang.Object
[<Android.Runtime.Register("android/app/job/JobScheduler", DoNotGenerateAcw=true)>]
type JobScheduler = class
    inherit Object
Inheritance
JobScheduler
Attributes

Remarks

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

See 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 #schedule(JobInfo). When the criteria declared are met, the system will execute this job on your application's android.app.job.JobService. You identify the service component that implements the logic for your job when you construct the JobInfo using android.app.job.JobInfo.Builder#Builder(int,android.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 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.

android.app.job.JobInfo.Builder#setRequiresBatteryNotLow(boolean) android.app.job.JobInfo.Builder#setRequiresDeviceIdle(boolean) android.app.job.JobInfo.Builder#setRequiresCharging(boolean) android.app.job.JobInfo.Builder#setRequiredNetworkType(int)

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 android.content.Context#getSystemService Context.getSystemService(Context.JOB_SCHEDULER_SERVICE).

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

In Android version android.os.Build.VERSION_CODES#LOLLIPOP, jobs had a maximum execution time of one minute. Starting with Android version android.os.Build.VERSION_CODES#M and ending with Android version android.os.Build.VERSION_CODES#R, jobs had a maximum execution time of 10 minutes. Starting from Android version 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.

<p class="caution"><strong>Note:</strong> Beginning with API 30 (android.os.Build.VERSION_CODES#R), JobScheduler will throttle runaway applications. Calling #schedule(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.

Java documentation for android.app.job.JobScheduler.

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Constructors

JobScheduler()
JobScheduler(IntPtr, JniHandleOwnership)

A constructor used when creating managed representations of JNI objects; called by the runtime.

Fields

PendingJobReasonApp
Obsolete.

The app is in a state that prevents the job from running (eg.

PendingJobReasonAppStandby
Obsolete.

The current standby bucket prevents the job from running.

PendingJobReasonBackgroundRestriction
Obsolete.

The app is restricted from running in the background.

PendingJobReasonConstraintBatteryNotLow
Obsolete.

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

PendingJobReasonConstraintCharging
Obsolete.

The requested charging constraint is not satisfied.

PendingJobReasonConstraintConnectivity
Obsolete.

The requested connectivity constraint is not satisfied.

PendingJobReasonConstraintContentTrigger
Obsolete.

The requested content trigger constraint is not satisfied.

PendingJobReasonConstraintDeviceIdle
Obsolete.

The requested idle constraint is not satisfied.

PendingJobReasonConstraintMinimumLatency
Obsolete.

The minimum latency has not transpired.

PendingJobReasonConstraintPrefetch
Obsolete.

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

PendingJobReasonConstraintStorageNotLow
Obsolete.

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

PendingJobReasonDeviceState
Obsolete.

The job is being deferred due to the device state (eg.

PendingJobReasonExecuting
Obsolete.

The job is currently running and is therefore not pending.

PendingJobReasonInvalidJobId
Obsolete.

The job doesn't exist.

PendingJobReasonJobSchedulerOptimization
Obsolete.

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

PendingJobReasonQuota
Obsolete.

The app has consumed all of its current quota.

PendingJobReasonUndefined
Obsolete.

There is no known reason why the job is pending.

PendingJobReasonUser
Obsolete.

JobScheduler is respecting one of the user's actions (eg.

ResultFailure

Returned from #schedule(JobInfo) if a job wasn't scheduled successfully.

ResultSuccess

Returned from #schedule(JobInfo) if this job has been successfully scheduled.

Properties

AllPendingJobs
Class

Returns the runtime class of this Object.

(Inherited from Object)
Handle

The handle to the underlying Android instance.

(Inherited from Object)
JniIdentityHashCode (Inherited from Object)
JniPeerMembers
Namespace

Get the namespace this JobScheduler instance is operating in.

PeerReference (Inherited from Object)
PendingJobsInAllNamespaces

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

ThresholdClass

This API supports the Mono for Android infrastructure and is not intended to be used directly from your code.

ThresholdType

This API supports the Mono for Android infrastructure and is not intended to be used directly from your code.

Methods

Cancel(Int32)

Cancel the specified job.

CancelAll()

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

CancelInAllNamespaces()

Cancel <em>all</em> jobs that have been scheduled by the calling application, regardless of namespace.

CanRunUserInitiatedJobs()

Returns true if the calling app currently holds the android.Manifest.permission#RUN_USER_INITIATED_JOBS permission, allowing it to run user-initiated jobs.

Clone()

Creates and returns a copy of this object.

(Inherited from Object)
Dispose() (Inherited from Object)
Dispose(Boolean) (Inherited from Object)
Enqueue(JobInfo, JobWorkItem)

Similar to #schedule, but allows you to enqueue work for a new <em>or existing</em> job.

Equals(Object)

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

(Inherited from Object)
ForNamespace(String)

Get a JobScheduler instance that is dedicated to a specific namespace.

GetHashCode()

Returns a hash code value for the object.

(Inherited from Object)
GetPendingJob(Int32)

Look up the description of a scheduled job.

GetPendingJobReason(Int32)

Returns a reason why the job is pending and not currently executing.

JavaFinalize()

Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.

(Inherited from Object)
Notify()

Wakes up a single thread that is waiting on this object's monitor.

(Inherited from Object)
NotifyAll()

Wakes up all threads that are waiting on this object's monitor.

(Inherited from Object)
Schedule(JobInfo)

Schedule a job to be executed.

SetHandle(IntPtr, JniHandleOwnership)

Sets the Handle property.

(Inherited from Object)
ToArray<T>() (Inherited from Object)
ToString()

Returns a string representation of the object.

(Inherited from Object)
UnregisterFromRuntime() (Inherited from Object)
Wait()

Causes the current thread to wait until it is awakened, typically by being <em>notified</em> or <em>interrupted</em>.

(Inherited from Object)
Wait(Int64, Int32)

Causes the current thread to wait until it is awakened, typically by being <em>notified</em> or <em>interrupted</em>, or until a certain amount of real time has elapsed.

(Inherited from Object)
Wait(Int64)

Causes the current thread to wait until it is awakened, typically by being <em>notified</em> or <em>interrupted</em>, or until a certain amount of real time has elapsed.

(Inherited from Object)

Explicit Interface Implementations

IJavaPeerable.Disposed() (Inherited from Object)
IJavaPeerable.DisposeUnlessReferenced() (Inherited from Object)
IJavaPeerable.Finalized() (Inherited from Object)
IJavaPeerable.JniManagedPeerState (Inherited from Object)
IJavaPeerable.SetJniIdentityHashCode(Int32) (Inherited from Object)
IJavaPeerable.SetJniManagedPeerState(JniManagedPeerStates) (Inherited from Object)
IJavaPeerable.SetPeerReference(JniObjectReference) (Inherited from Object)

Extension Methods

JavaCast<TResult>(IJavaObject)

Performs an Android runtime-checked type conversion.

JavaCast<TResult>(IJavaObject)
GetJniTypeName(IJavaPeerable)

Applies to