android - JobScheduler 不重复作业

标签 android android-jobscheduler

我正在使用 JobScheduler.setPeriodic() 来重复我的 JobIntentService。它第一次工作但从不重复。运行于安卓7.0

并发检查.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.

关于android - JobScheduler 不重复作业,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48248172/

相关文章:

android - Job Scheduler 间隔被调用的方式太少了

c# - 如何在 Xamarin Android 中实现 JobScheduler

java - 使用 JobScheduler 进行基于时间的通知

android - Android中的ActivityThread异常?

Android auto - 如何启用开发者模式

android - 使用对话框主题运行 Activity

android - 如何启动此 Activity 使用 adb shell am start -D -d pg/xx。 Activity 名称为 Main$Activity

java - onActivityResult 未从适配器调用

android - 何时调用 JobScheduler.schedule()

Android JobScheduler setRequiresDeviceIdle