-1

I have the following codes in my project but when i run it on my android emulator, it does not print any logs as it is supposed to do every 15 minutes.

public class JobSchedulerService extends JobService {

JobParameters params;
DoItTask doIt;

@Override
public boolean onStartJob(JobParameters params) {
    this.params = params;
    Log.d("TestService", "Work to be called from here");
    doIt = new DoItTask();
    doIt.execute();
    return false;
}

@Override
public boolean onStopJob(JobParameters params) {
    Log.d("TestService", "System calling to stop the job here");
    if (doIt != null)
        doIt.cancel(true);
    return false;
}

private class DoItTask extends AsyncTask<Void, Void, Void> {
    @Override
    protected void onPostExecute(Void aVoid) {
        Log.d("DoItTask", "Clean up the task here and call jobFinished...");
        jobFinished(params, false);
        super.onPostExecute(aVoid);
    }

    @Override
    protected Void doInBackground(Void... params) {
        Log.d("DoItTask", "Working here...");
        return null;
    }
}

}

and I call this in my mainactivity java

ComponentName componentName = new ComponentName(getApplicationContext(), JobSchedulerService.class);
    JobInfo jobInfo = new JobInfo.Builder(1, componentName).setPeriodic(900002).build();

I also have this in my mainfest under the application tag

<service android:name=".JobSchedulerService"
        android:permission="android.permission.BIND_JOB_SERVICE" />
Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
helpmeplease
  • 101
  • 1
  • 1
  • 9
  • Where is your call [to `schedule()`](https://developer.android.com/reference/android/app/job/JobScheduler.html#schedule(android.app.job.JobInfo))? – CommonsWare Jan 07 '18 at 22:13
  • *am I supped to add that after.build()?* - read the docs man – Tim Jan 07 '18 at 22:18

1 Answers1

0

To use JobScheduler, you need to:

  • Create a JobInfo, as you are doing
  • Get an instance of JobScheduler via getSystemService()
  • Call schedule() on the JobScheduler, passing it the JobInfo
CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491