@Override public int onStartCommand(@Nullable final Intent intent, int flags, final int startId) { synchronized (mMonitor) { mStartIds.add(startId); mLastStartId = startId; } JobConfig.getExecutorService().execute(new Runnable() { @Override public void run() { try { PlatformAlarmService.runJob(intent, PlatformAlarmServiceExact.this, CAT); } finally { // call here, our own wake lock could be acquired too late JobProxy.Common.completeWakefulIntent(intent); stopSelfIfNecessary(startId); } } }); return START_NOT_STICKY; }
@Override public boolean onStartJob(final JobParameters params) { JobConfig.getExecutorService().execute(new Runnable() { @Override public void run() {
/** * Helper method to schedule a request on a background thread. This is helpful to avoid IO operations * on the main thread. The callback notifies you about the job ID or a possible failure. * * @param callback The callback which is invoked after the request has been scheduled. */ public void scheduleAsync(@NonNull final JobScheduledCallback callback) { JobPreconditions.checkNotNull(callback); JobConfig.getExecutorService().execute(new Runnable() { @Override public void run() { try { int jobId = schedule(); callback.onJobScheduled(jobId, getTag(), null); } catch (Exception e) { callback.onJobScheduled(JobScheduledCallback.JOB_ID_ERROR, getTag(), e); } } }); }
/** * Helper method to schedule a daily job on a background thread. This is helpful to avoid IO operations * on the main thread. The callback notifies you about the job ID or a possible failure. For more * information about scheduling daily jobs see {@link #schedule(JobRequest.Builder, long, long)}. * * @param callback The callback which is invoked after the request has been scheduled. */ public static void scheduleAsync(@NonNull final JobRequest.Builder baseBuilder, final long startMs, final long endMs, @NonNull final JobRequest.JobScheduledCallback callback) { JobPreconditions.checkNotNull(callback); JobConfig.getExecutorService().execute(new Runnable() { @Override public void run() { try { int jobId = schedule(baseBuilder, startMs, endMs); callback.onJobScheduled(jobId, baseBuilder.mTag, null); } catch (Exception e) { callback.onJobScheduled(JobRequest.JobScheduledCallback.JOB_ID_ERROR, baseBuilder.mTag, e); } } }); }
private void waitUntilScheduled() throws Exception { final CountDownLatch latch = new CountDownLatch(1); JobConfig.getExecutorService().execute(new Runnable() { @Override public void run() { latch.countDown(); } }); latch.await(50, TimeUnit.SECONDS); } }
public synchronized Future<Job.Result> execute(@NonNull Context context, @NonNull JobRequest request, @Nullable Job job, @NonNull Bundle transientExtras) { mStartingRequests.remove(request); if (job == null) { CAT.w("JobCreator returned null for tag %s", request.getTag()); return null; } if (job.isFinished()) { throw new IllegalStateException(String.format(Locale.ENGLISH, "Job for tag %s was already run, a creator should always create a new Job instance", request.getTag())); } job.setContext(context).setRequest(request, transientExtras); CAT.i("Executing %s, context %s", request, context.getClass().getSimpleName()); mJobs.put(request.getJobId(), job); return JobConfig.getExecutorService().submit(new JobCallable(job)); }
@Override public int onStartCommand(@Nullable final Intent intent, int flags, final int startId) { synchronized (mMonitor) { mStartIds.add(startId); mLastStartId = startId; } JobConfig.getExecutorService().execute(new Runnable() { @Override public void run() { try { PlatformAlarmService.runJob(intent, PlatformAlarmServiceExact.this, CAT); } finally { // call here, our own wake lock could be acquired too late JobProxy.Common.completeWakefulIntent(intent); stopSelfIfNecessary(startId); } } }); return START_NOT_STICKY; }
@Override public boolean onStartJob(final JobParameters params) { JobConfig.getExecutorService().execute(new Runnable() { @Override public void run() {
/** * Helper method to schedule a request on a background thread. This is helpful to avoid IO operations * on the main thread. The callback notifies you about the job ID or a possible failure. * * @param callback The callback which is invoked after the request has been scheduled. */ public void scheduleAsync(@NonNull final JobScheduledCallback callback) { JobPreconditions.checkNotNull(callback); JobConfig.getExecutorService().execute(new Runnable() { @Override public void run() { try { int jobId = schedule(); callback.onJobScheduled(jobId, getTag(), null); } catch (Exception e) { callback.onJobScheduled(JobScheduledCallback.JOB_ID_ERROR, getTag(), e); } } }); }
/** * Helper method to schedule a daily job on a background thread. This is helpful to avoid IO operations * on the main thread. The callback notifies you about the job ID or a possible failure. For more * information about scheduling daily jobs see {@link #schedule(JobRequest.Builder, long, long)}. * * @param callback The callback which is invoked after the request has been scheduled. */ public static void scheduleAsync(@NonNull final JobRequest.Builder baseBuilder, final long startMs, final long endMs, @NonNull final JobRequest.JobScheduledCallback callback) { JobPreconditions.checkNotNull(callback); JobConfig.getExecutorService().execute(new Runnable() { @Override public void run() { try { int jobId = schedule(baseBuilder, startMs, endMs); callback.onJobScheduled(jobId, baseBuilder.mTag, null); } catch (Exception e) { callback.onJobScheduled(JobRequest.JobScheduledCallback.JOB_ID_ERROR, baseBuilder.mTag, e); } } }); }
public synchronized Future<Job.Result> execute(@NonNull Context context, @NonNull JobRequest request, @Nullable Job job, @NonNull Bundle transientExtras) { mStartingRequests.remove(request); if (job == null) { CAT.w("JobCreator returned null for tag %s", request.getTag()); return null; } if (job.isFinished()) { throw new IllegalStateException(String.format(Locale.ENGLISH, "Job for tag %s was already run, a creator should always create a new Job instance", request.getTag())); } job.setContext(context).setRequest(request, transientExtras); CAT.i("Executing %s, context %s", request, context.getClass().getSimpleName()); mJobs.put(request.getJobId(), job); return JobConfig.getExecutorService().submit(new JobCallable(job)); }