我有一个工作计划程序,用于安排每天/每周/每月的备份工作服务。但是一旦我致电jobscheduler.schedule(jobInfo)
,工作就会立即开始。
请紧记,我在调用jobBuilder.setPriodic(duration)
时仅使用间隔毫秒而不是弹性时间(因为替代方法需要API级别24)
我想知道
如何以特定的延迟时间延迟开始这项工作。
ComponentName backupJob = new ComponentName(TelloApplication.applicationContext, BackupJobService.class);
JobInfo.Builder jobBuilder = new JobInfo.Builder(TelloConstants.BACKUP_ID, backupJob);
jobBuilder.setRequiredNetworkType(JobInfo.NETWORK_TYPE_UNMETERED);
jobBuilder.setPeriodic(duration);
JobScheduler scheduler = (JobScheduler) getActivity().getSystemService(Context.JOB_SCHEDULER_SERVICE);
if (duration == 0) {
scheduler.cancel(TelloConstants.BACKUP_ID);
} else {
scheduler.schedule(jobBuilder.build());
}
添加logcat
2018-12-05 12:26:16.716 16871-16871/com.udna.tellotalk.exp.dev D/05-Dec-2018 12:26 PM :: Scheduling Job For 604800 Seconds
2018-12-05 12:26:16.765 16871-16871/com.udna.tellotalk.exp.dev W/05-Dec-2018 12:26 PM :: OnStartJob initiating Sign-inWed Dec 05 12:26:16 GMT+05:00 2018
2018-12-05 12:26:16.765 16871-16871/com.udna.tellotalk.exp.dev W/05-Dec-2018 12:26 PM :: OnStartJob initiating Sign-inWed Dec 05 12:26:16 GMT+05:00 2018
2018-12-05 12:26:16.768 16871-16871/com.udna.tellotalk.exp.dev W/05-Dec-2018 12:26 PM :: Sign-in success, starting service
2018-12-05 12:26:16.768 16871-16871/com.udna.tellotalk.exp.dev W/05-Dec-2018 12:26 PM :: Sign-in success, starting service
2018-12-05 12:26:16.775 16871-16871/com.udna.tellotalk.exp.dev D/com.udna.tellotalk.services.TelloBackUpService: onCreate: TELLO BACKUP STARTED
2018-12-05 12:26:16.776 16871-16871/com.udna.tellotalk.exp.dev D/com.udna.tellotalk.services.TelloBackUpService: onStartCommand:
2018-12-05 12:26:16.784 16871-16871/com.udna.tellotalk.exp.dev D/com.udna.tellotalk.services.TelloBackUpService: sendServiceReference:
2018-12-05 12:26:16.786 16871-16871/com.udna.tellotalk.exp.dev D/05-Dec-2018 12:26 PM :: Starting background backup for messages