1

I implement job scheduler in my Android app. For this i apply framework JobScheduler.

JobScheduler jobScheduler = (JobScheduler)getSystemService(JOB_SCHEDULER_SERVICE);
    ComponentName jobService =
            new ComponentName(getBaseContext(), ServiceAppControl.class);
    JobInfo jobInfo =
            new JobInfo.Builder(MYJOBID, jobService)
                    .setRequiredNetworkType(JobInfo.NETWORK_TYPE_UNMETERED)
                    .setPeriodic(100)
                    .setPersisted(true)
                    .build();
    jobScheduler.schedule(jobInfo);

manifest.xml

<service
        android:name=".services.ServiceAppControl"
        android:permission="android.permission.BIND_JOB_SERVICE"
        android:exported="true"/>

ServiceAppControl

public class ServiceAppControl extends JobService {

@Override
public boolean onStartJob(JobParameters params) {
    Log.d("Control", "onStartJob");
    return false;
}

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

I did everything right? Logging is performed only once in about 10 minutes.

---EDIT---

I found such entries in the logcat. Could this mean something?

10-12 13:40:48.324 24072-24072/ru.test.testjobscheduler W/JobInfo: Specified interval for 1001 is +1s0ms. Clamped to +15m0s0ms 10-12 13:40:48.324 24072-24072/ru.test.testjobscheduler W/JobInfo: Specified flex for 1001 is +1s0ms. Clamped to +5m0s0ms

user1854307
  • 580
  • 4
  • 8
  • 21
  • Are you sure you have the correct network connection available for the job to run? `setRequiredNetworkType(JobInfo.NETWORK_TYPE_UNMETERED)` and from documentation: "Bear in mind that calling this function defines network as a strict requirement for your job. If the network requested is not available your job will never run.". Try removing this setting and check if the job is run as expected. – pleft Oct 11 '17 at 12:56
  • yes, wi-fi is used as a connection. I tried without this line of code, but in this case it does not work either. – user1854307 Oct 11 '17 at 13:00
  • and no related logcat errors/warnings? – pleft Oct 11 '17 at 13:21
  • No, in logcat record error or warning not exist. – user1854307 Oct 11 '17 at 13:47
  • I edited my question. – user1854307 Oct 12 '17 at 10:44
  • https://stackoverflow.com/a/38774104/3635454 – pleft Oct 12 '17 at 10:47

1 Answers1

2

JobScheduler works with a minimum periodic of 15 mins change to .setPeriodic(15 * 60 * 1000)

Rex
  • 57
  • 8