I'm using the following code to make a job run every time there is available internet. What I want in addition is, after the service is triggered (due to available connection) I want that service to continue running g periodically (every 30 seconds) as long as there is internet and then when the connectivity is no longer available, the service should stop and only resume the next time there is internet.
FirebaseJobDispatcher jobDispatcher = new FirebaseJobDispatcher(new GooglePlayDriver(MainActivity.this));
.setTag("JobService")
.setRecurring(true)
.setLifetime(Lifetime.FOREVER)
.setService(JobService.class)
.setTrigger(Trigger.executionWindow(0,10))
.setReplaceCurrent(true)
.setRetryStrategy(RetryStrategy.DEFAULT_EXPONENTIAL);
builder.addConstraint(Constraint.ON_UNMETERED_NETWORK);
jobDispatcher.mustSchedule(builder.build());
I thought of making the JobService itself schedule the next time it is going to run (in thirty seconds) and after the time is up, test if there is internet then ok else I'll call the Onstop method but it didn't feel like the right approach to solve this.