job scheduling - job scheduler in android N with less then 15 minutes interval -
part of question, how can set job less 15 minutes interval in "nougat", answerd "blizzard" in answer here:
job scheduler not running on android n
explained problem , suggested use following workaround:
jobinfo jobinfo; if (build.version.sdk_int >= build.version_codes.n) { jobinfo = new jobinfo.builder(job_id, servicename) .setminimumlatency(refresh_interval) .setextras(bundle).build(); } else { jobinfo = new jobinfo.builder(job_id, servicename) .setperiodic(refresh_interval) .setextras(bundle).build(); }
however, using suggested
.setminimumlatency(refresh_interval)
just starts job once;
how periodic period of around 30 seconds on android nougat device (not using handler or alarm manager)?
i struggled same thing when wanted setup job refresh small part of data. found out solution problem may setting job 1 more time same id after calledjobfinished(jobparameters, boolean)
. think should work every time on main thread.
my function setup job looks this:
jobinfo generaterefreshtokenjobinfo(long periodtime){ jobinfo.builder jobbuilder = new jobinfo.builder(1l, new componentname(mcontext, jobservice.class)); jobbuilder.setminimumlatency(periodtime); jobbuilder.setoverridedeadline((long)(periodtime * 1.05)); jobbuilder.setrequiresdeviceidle(false); return jobbuilder.build(); }
when finish work after first call of job call in main thread
jobfinished(mjobparameters, true); registerrefreshjob(5*60*1000l);
this reschedule job 1 more time same amount of time on same id. when device in idle state still have take under consideration lack of wake locks in doze job may not started wish. mentioned in https://developer.android.com/about/versions/nougat/android-7.0-changes.html
if device stationary time after entering doze, system applies rest of doze restrictions powermanager.wakelock, alarmmanager alarms, gps, , wi-fi scans. regardless of whether or doze restrictions being applied, system wakes device brief maintenance windows, during applications allowed network access , can execute deferred jobs/syncs.
Comments
Post a Comment