1

I have tried all the below methods from evernote-android-job. Seems the schedulePeriodicJob method is running in some interval and the scheduleAdvancedJob method run only once.

Help me how to set values for setExecutionWindow, setExact and setPeriodic with some example?

private void scheduleAdvancedJob() {
    PersistableBundleCompat extras = new PersistableBundleCompat();
    extras.putString("key", "Hello world");

    int jobId = new JobRequest.Builder(DemoSyncJob.TAG)
            .setExecutionWindow(30_000L, 40_000L)
            .setBackoffCriteria(5_000L, JobRequest.BackoffPolicy.EXPONENTIAL)
            .setRequiresCharging(true)
            .setRequiresDeviceIdle(false)
            .setRequiredNetworkType(JobRequest.NetworkType.CONNECTED)
            .setExtras(extras)
            .setRequirementsEnforced(true)
            .setUpdateCurrent(true)
            .build()
            .schedule();
}

private void schedulePeriodicJob() {
    int jobId = new JobRequest.Builder(DemoSyncJob.TAG)
            .setPeriodic(TimeUnit.MINUTES.toMillis(15), TimeUnit.MINUTES.toMillis(5))
            .build()
            .schedule();
}

private void scheduleExactJob() {
    int jobId = new JobRequest.Builder(DemoSyncJob.TAG)
            .setExact(20_000L)
            .build()
            .schedule();
}
Gvtha
  • 1,463
  • 1
  • 11
  • 18

1 Answers1

0

I've faced same schenario and used this one and get success. you can also try it.

public class RunFSJob extends Job {

    public static final String TAG = "JOB_FOR_START_SIGNARSERVICE";

    @Override
    @NonNull
    protected Result onRunJob(@NonNull Params params) {

        try {

            deleteCache(getContext().getApplicationContext());

            getContext().getApplicationContext().startService(new Intent(getContext().getApplicationContext(), SignalRService.class));

            Log.v("schedulePeriodicJob(15)", "JOB Done");

            cancel();

            Log.v("schedulePeriodicJob(15)", "JOB cancled");

            schedulePeriodicJob();

            Log.v("schedulePeriodicJob(15)", "JOB scheduled again from RunFSJob");

        } catch (Exception e) {
            e.printStackTrace();
        }
        return Job.Result.SUCCESS;
    }
}
  • First of all use periodic job and schedule the same job everytime from onRunJob() method. you have to cancel the last job ,too.

  • Hope it will help you.

mcd
  • 1,434
  • 15
  • 31