i have scheduled a job which will repeat every 10 sec. i have tried with job scheduler with setMinimumLatency and setOverrideDeadline but my job is not repeating. i have followed different tutorial and blogs , done everything as showed there but not working well.
my code below:
manifest:
<service android:name=".JobServiceClass"
android:permission="android.permission.BIND_JOB_SERVICE"
android:exported="true"
>
</service>
JobServiceUtils:
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
public static void scheduleJob(Context context)
{
ComponentName componentName=new ComponentName(context,JobServiceClass.class);
JobInfo.Builder jobInfo=new JobInfo.Builder(1000,componentName);
jobInfo.setPersisted(true);
jobInfo.setMinimumLatency(10000);
jobInfo.setOverrideDeadline(10000);
JobScheduler jobScheduler=(JobScheduler)context.getSystemService(Context.JOB_SCHEDULER_SERVICE);
if (jobScheduler!=null){
jobScheduler.schedule(jobInfo.build());
}
}
JobServiceClass:
@Override
public boolean onStartJob(JobParameters params) {
Toast.makeText(getApplicationContext(),"Job service thread",Toast.LENGTH_LONG).show();
asynctaskClass=new AsynctaskClass(getApplicationContext(), new AsynctaskResult() {
@Override
public void asyncTaskResult(String result) {
}
});
return true;
}
@Override
public boolean onStopJob(JobParameters params) {
Toast.makeText(getApplicationContext(),"Job service thread stop",Toast.LENGTH_LONG).show();
return true;
}
initialization from activity:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
JobServiceUtils.scheduleJob(MainActivity.this);
}else {
Intent intent1 = new Intent(this, ServiceClass.class);
intent1.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startService(intent1);
}
can anyone tell me the exact thing what i am missing here