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 ...

Get Asynchronous Android Programming - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.