JobScheduler不重复工作

gal*_*irl 5 android android-jobscheduler

我正在使用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");
        }
Run Code Online (Sandbox Code Playgroud)

Ste*_*etz 11

可安排工作的最短时间为15分钟.如果设置为小于15分钟的值,则作业将使用15分钟.

请参阅:JobInfo中的MIN_PERIOD_MILLIS.

另外,请在代码中看到此注释:

查询定期计划作业允许的最小间隔.尝试在调度作业时声明一个较小的句点将导致作业仍然是定期的,但将在此有效期内运行.您的间隔的重复任务将需要一些其他服务,可能警报管理器将为您工作.