1

我的活动.java

JobInfo jobInfo = new JobInfo.Builder(jobId,
            new ComponentName(getApplicationContext(), MyService.class))
            .setPeriodic(TimeUnit.MINUTES.toMillis(1))
            .setPersisted(true)
            .build();
    JobScheduler scheduler =
            (JobScheduler) getSystemService(Context.JOB_SCHEDULER_SERVICE);
    int s = scheduler.schedule(jobInfo);

我的服务.java

public class MyService extends JobService{
@Override
public boolean onStartJob(JobParameters params) {
    Log.v("SUCCESS", "Job started!");
    jobFinished(params, true);
    return false;
}

@Override
public boolean onStopJob(JobParameters params) {
    return false;
}

我试图创建一个每分钟运行一次的jobService,但是如果我在方法.setPeriodic(TimeUnit.MINUTES.toMillis(1))中输入1,它似乎不起作用但是如果我把15放入它似乎工作美好的。谁能告诉我如何在每分钟使用 Jobservice 后启动 myservice ?

4

1 回答 1

1

Minimum interval for JobScheduler is 15 mins that's why 1 min interval is not working and 15 min is working

于 2017-11-14T02:44:44.697 回答