Implementing the JobService
Our JobService
subclass is the entity that is going to do the hard work and receive the callbacks as soon as all the criteria specified in the JobInfo
are met. To implement our own service, we have to extend from JobService
and override the start and stop callbacks, as shown in the following code:
public class AccountBackupJobService extends JobService { @Override public boolean onStartJob(JobParameters params) { // Start your job here return false; } @Override public boolean onStopJob(JobParameters params) { // Stop your job here return false; } }
The onStartJob
callback function runs on the main thread, and if the job needs to do asynchronous processing then it should return true
to indicate it's still doing work on a background thread. The callback
function also receives the extra parameters specified in the JobInfo
bundle.
onStopJob
is automatically invoked by the system when it requires to cancel the job...