title: Start service with JobScheduler on Android O
body: <p>I'm trying to start a IntentService to register to a firebase cloud messaging on Android O.</p>
  
  <p>On Android O it's not allowed to start a Intent Service "in a situation when it isn't permitted" and every one tells me to use a JobService but not how to use it.</p>
  
  <p><strong>What constraints should the JobInfo.Builder have in order to have a "situation where it's permitted", i keep getting the same IllegalStateException</strong> </p>
  
  <p>Here's my JobService</p>
  
  <pre><code>@Override
  public boolean onStartJob(JobParameters params) {
      Intent intent = new Intent(this, RegistrationIntentService.class);
      getApplicationContext().startService(intent);
      return false;
  }
  
  @Override
  public boolean onStopJob(JobParameters params) {
      return false;
  }
  
  public static void scheduleJob(Context context) {
      ComponentName serviceComponent = new ComponentName(context, MyJobService.class);
      JobInfo.Builder builder = new JobInfo.Builder(MyJobService.JOB_ID, serviceComponent);
      builder.setMinimumLatency(1 * 1000); // wait at least
      JobScheduler jobScheduler = context.getSystemService(JobScheduler.class);
      if(jobScheduler != null) jobScheduler.schedule(builder.build());
  }
  </code></pre>