@Test public void testCancel() { JobInfo job = JobCreator.create(application).setRequiresDeviceIdle(true).build(); jobScheduler.schedule(job); JobInfo job2 = JobCreator.create(application).setRequiresDeviceIdle(true).build(); jobScheduler.schedule(job2); assertJobSchedulerContains(job.getId(), job2.getId()); jobScheduler.cancel(job.getId()); assertJobSchedulerContains(job2.getId()); jobScheduler.cancel(job2.getId()); assertJobSchedulerContains(); }
public void cancel(int jobId) { synchronized (JobStore.LOCK) { JobStatus jobStatus = jobStore.getJob(jobId); if (jobStatus != null) { jobStore.remove(jobId); getSchedulerForTag(context, jobStatus.getSchedulerTag()).cancel(jobId); } } }
JobScheduler { public void cancel(int jobId) { synchronized (JobStore.LOCK) { JobStatus jobStatus = jobStore.getJob(jobId); if (jobStatus != null) { jobStore.remove(jobId); getSchedulerForTag(context, jobStatus.getSchedulerTag()).cancel(jobId); } } } }
JobScheduler { public void cancel(int jobId) { synchronized (JobStore.LOCK) { JobStatus jobStatus = jobStore.getJob(jobId); if (jobStatus != null) { jobStore.remove(jobId); getSchedulerForTag(context, jobStatus.getSchedulerTag()).cancel(jobId); } } } private  JobScheduler(Context context); }
JobScheduler { public void cancel(int jobId) { synchronized (JobStore.LOCK) { JobStatus jobStatus = jobStore.getJob(jobId); if (jobStatus != null) { jobStore.remove(jobId); getSchedulerForTag(context, jobStatus.getSchedulerTag()).cancel(jobId); } } } private  JobScheduler(Context context); static synchronized JobScheduler get(Context context); int schedule(JobInfo job); void cancel(int jobId); void cancelAll(); @NonNull List<JobInfo> getAllPendingJobs(); @Nullable JobInfo getPendingJob(int jobId); @RestrictTo(RestrictTo.Scope.LIBRARY) void onJobCompleted(int jobId, boolean needsReschedule); @RestrictTo(RestrictTo.Scope.LIBRARY) List<JobStatus> getJobsByScheduler(String scheduler); @RestrictTo(RestrictTo.Scope.LIBRARY) JobStatus getJob(int jobId); @RestrictTo(RestrictTo.Scope.LIBRARY) void addJob(JobStatus jobStatus); @RestrictTo(RestrictTo.Scope.LIBRARY) void removeJob(int jobId); }
JobScheduler { public void cancel(int jobId) { synchronized (JobStore.LOCK) { JobStatus jobStatus = jobStore.getJob(jobId); if (jobStatus != null) { jobStore.remove(jobId); getSchedulerForTag(context, jobStatus.getSchedulerTag()).cancel(jobId); } } } private  JobScheduler(Context context); static synchronized JobScheduler get(Context context); int schedule(JobInfo job); void cancel(int jobId); void cancelAll(); @NonNull List<JobInfo> getAllPendingJobs(); @Nullable JobInfo getPendingJob(int jobId); @RestrictTo(RestrictTo.Scope.LIBRARY) void onJobCompleted(int jobId, boolean needsReschedule); @RestrictTo(RestrictTo.Scope.LIBRARY) List<JobStatus> getJobsByScheduler(String scheduler); @RestrictTo(RestrictTo.Scope.LIBRARY) JobStatus getJob(int jobId); @RestrictTo(RestrictTo.Scope.LIBRARY) void addJob(JobStatus jobStatus); @RestrictTo(RestrictTo.Scope.LIBRARY) void removeJob(int jobId); static final int RESULT_FAILURE; static final int RESULT_SUCCESS; }