JobService.OnStopJob(JobParameters) Method

Definition

This method is called if the system has determined that you must stop execution of your job even before you've had a chance to call #jobFinished(JobParameters, boolean).

[Android.Runtime.Register("onStopJob", "(Landroid/app/job/JobParameters;)Z", "GetOnStopJob_Landroid_app_job_JobParameters_Handler")]
public abstract bool OnStopJob (Android.App.Job.JobParameters? params);
[<Android.Runtime.Register("onStopJob", "(Landroid/app/job/JobParameters;)Z", "GetOnStopJob_Landroid_app_job_JobParameters_Handler")>]
abstract member OnStopJob : Android.App.Job.JobParameters -> bool

Parameters

params
JobParameters

The parameters identifying this job, similar to what was supplied to the job in the #onStartJob(JobParameters) callback, but with the stop reason included.

Returns

true to indicate to the JobManager whether you'd like to reschedule this job based on the retry criteria provided at job creation-time; or false to end the job entirely (or, for a periodic job, to reschedule it according to its requested periodic criteria). Regardless of the value returned, your job must stop executing.

Attributes

Remarks

This method is called if the system has determined that you must stop execution of your job even before you've had a chance to call #jobFinished(JobParameters, boolean). Once this method is called, you no longer need to call #jobFinished(JobParameters, boolean).

This may happen if the requirements specified at schedule time are no longer met. For example you may have requested WiFi with android.app.job.JobInfo.Builder#setRequiredNetworkType(int), yet while your job was executing the user toggled WiFi. Another example is if you had specified android.app.job.JobInfo.Builder#setRequiresDeviceIdle(boolean), and the phone left its idle state. There are many other reasons a job can be stopped early besides constraints no longer being satisfied. JobParameters#getStopReason() will return the reason this method was called. You are solely responsible for the behavior of your application upon receipt of this message; your app will likely start to misbehave if you ignore it.

Once this method returns (or times out), the system releases the wakelock that it is holding on behalf of the job.

<p class="note"> Any JobInfo.Builder#setUserInitiated(boolean) user-initiated job cannot be rescheduled when stopped by the user via a system provided affordance (such as the Task Manager). In such situations, the returned value from this method call is always treated as false.

<p class="caution"><strong>Note:</strong> When a job is stopped and rescheduled via this method call, the deadline constraint is excluded from the rescheduled job's constraint set. The rescheduled job will run again once all remaining constraints are satisfied.

Java documentation for android.app.job.JobService.onStopJob(android.app.job.JobParameters).

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