我需要使用setPeriodic指令每4或5小时启动一次服务,但是每次更改setPeriodic指令的参数值时,它会每3分钟在max:/午餐一次。
我的代码:
mScheduler = (JobScheduler) getSystemService(JOB_SCHEDULER_SERVICE);
RadioGroup networkOptions = (RadioGroup) findViewById(R.id.networkOptions);
int selectedNetworkID = networkOptions.getCheckedRadioButtonId();
int selectedNetworkOption = JobInfo.NETWORK_TYPE_NONE;
ComponentName serviceName = new ComponentName(getPackageName(),
NotificationJobService.class.getName());
JobInfo.Builder builder = new JobInfo.Builder(JOB_ID, serviceName)
.setRequiredNetworkType(selectedNetworkOption);
int seekBarInteger = mSeekBar.getProgress();
boolean seekBarSet = seekBarInteger > 0;
//Set the job parameters based on the periodic switch.
builder.setPeriodic(1000*60*400);//3mins =240000//\1000*60*400
//builder.setMinimumLatency(1000*60*10);
//builder.setOverrideDeadline(1000*60*15);
//Schedule the job and notify the user
JobInfo myJobInfo = builder.build();
mScheduler.schedule(myJobInfo);
Toast.makeText(this, R.string.job_scheduled, Toast.LENGTH_SHORT).show();
}
/**
* onClick method for cancelling all existing jobs
*/
private void cancelJobs() {
if (mScheduler != null){
mScheduler.cancelAll();
mScheduler = null;
Toast.makeText(this, R.string.jobs_canceled, Toast.LENGTH_SHORT).show();
}
}
}