I have a job as under
public class MyPeriodicJob extends JobService{
@Override
public boolean onStartJob(JobParameters jobParameters) {
// do something (but context is needed)
return false;
}
@Override
public boolean onStopJob(JobParameters jobParameters) {
return false;
}
}
It is started in MainActivity
private void scheduleJob(){
JobScheduler jobScheduler = (JobScheduler)getApplicationContext()
.getSystemService(JOB_SCHEDULER_SERVICE);
ComponentName componentName = new ComponentName(this,
MyPeriodicJob.class);
JobInfo jobInfo = new JobInfo.Builder(1, componentName)
.setPeriodic(86400000)
.setPersisted(true).build();
jobScheduler.schedule(jobInfo);
}
The device may restart but the job is expected to persist. How can I pass context (which must persist) to the MyPeriodicJob ?