JobScheduler 不重复作业
JobScheduler not repeating job
我正在使用 JobScheduler.setPeriodic() 重复我的 JobIntentService。它第一次工作但从不重复。 运行 在 Android 7.0
ConcurrentCheck.java
int mdelaymilles = 30000;
JobScheduler jobScheduler = (JobScheduler) mActivity.getSystemService(JOB_SCHEDULER_SERVICE);
ComponentName componentName = new ComponentName(mActivity, ConcurrentCheckService.class);
JobInfo jobInfo = new JobInfo.Builder(JOB_ID, componentName)
.setPeriodic(mdelaymilles)
.setRequiredNetworkType(JobInfo.NETWORK_TYPE_ANY)
.build();
int resultCode = jobScheduler.schedule(jobInfo);
if (resultCode == JobScheduler.RESULT_SUCCESS) {
Log.d(LOG_TAG, "Job scheduled!");
Intent intent = new Intent();
intent.putExtra(LAST_POSITION, lastPosition);
JobIntentService.enqueueWork(mActivity, ConcurrentCheckService.class, JOB_ID, intent);
} else {
Log.d(LOG_TAG, "Job not scheduled");
}
作业可以安排的最短时间为 15 分钟。如果设置为小于 15 分钟的值,作业将使用 15 分钟。
请参阅:MIN_PERIOD_MILLIS 中的 JobInfo。
另外,在代码中也看到这个comment:
Query the minimum interval allowed for periodic scheduled jobs.
Attempting to declare a smaller period that this when scheduling a job
will result in a job that is still periodic, but will run with this
effective period. A recurring task with your interval will need some
other service, possibly the Alarm Manager will work for you.
我正在使用 JobScheduler.setPeriodic() 重复我的 JobIntentService。它第一次工作但从不重复。 运行 在 Android 7.0
ConcurrentCheck.java
int mdelaymilles = 30000;
JobScheduler jobScheduler = (JobScheduler) mActivity.getSystemService(JOB_SCHEDULER_SERVICE);
ComponentName componentName = new ComponentName(mActivity, ConcurrentCheckService.class);
JobInfo jobInfo = new JobInfo.Builder(JOB_ID, componentName)
.setPeriodic(mdelaymilles)
.setRequiredNetworkType(JobInfo.NETWORK_TYPE_ANY)
.build();
int resultCode = jobScheduler.schedule(jobInfo);
if (resultCode == JobScheduler.RESULT_SUCCESS) {
Log.d(LOG_TAG, "Job scheduled!");
Intent intent = new Intent();
intent.putExtra(LAST_POSITION, lastPosition);
JobIntentService.enqueueWork(mActivity, ConcurrentCheckService.class, JOB_ID, intent);
} else {
Log.d(LOG_TAG, "Job not scheduled");
}
作业可以安排的最短时间为 15 分钟。如果设置为小于 15 分钟的值,作业将使用 15 分钟。
请参阅:MIN_PERIOD_MILLIS 中的 JobInfo。
另外,在代码中也看到这个comment:
Query the minimum interval allowed for periodic scheduled jobs. Attempting to declare a smaller period that this when scheduling a job will result in a job that is still periodic, but will run with this effective period. A recurring task with your interval will need some other service, possibly the Alarm Manager will work for you.