次の方法で共有


JobService.OnStartJob(JobParameters) Method

Definition

Called to indicate that the job has begun executing.

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

Parameters

params
JobParameters

Parameters specifying info about this job, including the optional extras configured with JobInfo.Builder#setExtras(android.os.PersistableBundle). This object serves to identify this specific running job instance when calling #jobFinished(JobParameters, boolean).

Returns

true if your service will continue running, using a separate thread when appropriate. false means that this job has completed its work.

Attributes

Remarks

Called to indicate that the job has begun executing. Override this method with the logic for your job. Like all other component lifecycle callbacks, this method executes on your application's main thread.

Return true from this method if your job needs to continue running. If you do this, the job remains active until you call #jobFinished(JobParameters, boolean) to tell the system that it has completed its work, or until the job's required constraints are no longer satisfied. For example, if the job was scheduled using JobInfo.Builder#setRequiresCharging(boolean) setRequiresCharging(true), it will be immediately halted by the system if the user unplugs the device from power, the job's #onStopJob(JobParameters) callback will be invoked, and the app will be expected to shut down all ongoing work connected with that job.

The system holds a wakelock on behalf of your app as long as your job is executing. This wakelock is acquired before this method is invoked, and is not released until either you call #jobFinished(JobParameters, boolean), or after the system invokes #onStopJob(JobParameters) to notify your job that it is being shut down prematurely.

Returning false from this method means your job is already finished. The system's wakelock for the job will be released, and #onStopJob(JobParameters) will not be invoked.

Java documentation for android.app.job.JobService.onStartJob(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