Sdílet prostřednictvím


JobParameters.DequeueWork Method

Definition

Dequeue the next pending JobWorkItem from these JobParameters associated with their currently running job.

[Android.Runtime.Register("dequeueWork", "()Landroid/app/job/JobWorkItem;", "GetDequeueWorkHandler", ApiSince=26)]
public virtual Android.App.Job.JobWorkItem? DequeueWork ();
[<Android.Runtime.Register("dequeueWork", "()Landroid/app/job/JobWorkItem;", "GetDequeueWorkHandler", ApiSince=26)>]
abstract member DequeueWork : unit -> Android.App.Job.JobWorkItem
override this.DequeueWork : unit -> Android.App.Job.JobWorkItem

Returns

Returns a new 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.)

Attributes

Remarks

Dequeue the next pending 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 JobService#jobFinished(JobParameters, boolean) yourself (otherwise you risk losing an upcoming JobWorkItem that is being enqueued at the same time).

Once you are done with the JobWorkItem returned by this method, you must call #completeWork(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 deqeueing the next one -- you can use #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 JobService#onStopJob(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:

{

Java documentation for android.app.job.JobParameters.dequeueWork().

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.

Applies to