Question: Retries + repeated period scheduling
See original GitHub issueHi!
First of all, I love this library its documentation. Having in consideration the pain of working with alarms on Android, this is kind of a must.
I have two usage cases for the library, and I’ve been through all the issues (opened and closed) but I haven’t been able to see anything related to what I’m looking for:
Retries
One of my use cases, is scheduling a job that’s triggered in two minutes. If there is no connectivity, then it’s useless so I used a backoff criteria to trigger the job again in 4,8,16 minutes. My questions are:
- Is there any way to say how many retries I want set up? Because Imagine I’m on a trip and I trigger the job. It would be there trying to triggering events forever. I don’t know if it makes a lot of sense, but I was just wondering…
Here is the code:
new JobRequest.Builder(DismissPendingFeedJob.TAG)
.setExact(timeInMillis)
.setPersisted(true)
.setBackoffCriteria(TWO_MINUTES, JobRequest.BackoffPolicy.EXPONENTIAL)
.setRequirementsEnforced(true)
.setUpdateCurrent(true)
.setRequiredNetworkType(JobRequest.NetworkType.CONNECTED)
.build()
.schedule();
- Instead of setting a custom requirement and a back-off criteria, the first it came to my head was using a broadcast receiver to check for connectivity and then triggering a job, but Lint complains about the connectivity change intent filter:
So that means it doesn’t work anymore from Android N. I guess there is an alternative (as the lint says) using the JobScheduler
or the GCMNetworkManager
. Is there anything I could do with Android Job?
Repeated period scheduling
From here I’ve seen there is a way to run a job at a specific time once a day, but as I’ve seen here, we have to reeschedule the periodic jobs from the first job. That means we should always return Result.RESCHEDULE
and override the reescheduling function in the job?
Thanks!!
Issue Analytics
- State:
- Created 7 years ago
- Comments:8
Top GitHub Comments
I’ve been so busy, but I wanted to ask something else. If you give me one more week Ill make a couple of more questions and I’ll try to make a PR updating documentation as well 😉
Got your point. So my use case is I start a service with Network as requirement and return RESCHEDULE from onRunJob() and in the service first step I check internet is there or not, if its not there then I stop the service. So the below method will start the service again when the network reconnects? public static void scheduleNetworkJob() { new JobRequest.Builder(TAG) .setExecutionWindow(TimeUnit.MINUTES.toMillis(1), TimeUnit.DAYS.toMillis(1)) .setRequiredNetworkType(JobRequest.NetworkType.UNMETERED) .build() .schedule(); }