Akhil Dabral
Akhil Dabral

Reputation: 900

Android Job scheduler behavior when device goes for deep sleep

I am currently working with an android application that uses android job scheduler to call an api at certain interval(lets say every 4 hours). Suppose my device is not on charge and there is no activity being done on it, so it goes to sleep after some time(lets say after 1 hour of last api call). Now my device wakes up after 5 hours due to some activity that I did deleberatly. Will the scheduler call the api immediately(as its more than 4 hrs since last call)? or will it wait for next 3 hours to run the job? (*I have not acquired the wake lock in this case so the device will go to sleep.)

Upvotes: 3

Views: 2165

Answers (1)

Anton Kazakov
Anton Kazakov

Reputation: 2774

I think you by Deep Sleep you mean Doze. When your device in doze mode your JobServices will not trigger. Periodic job can't be exact. A job is either exact or periodic. So periodic will trigger while in maintenance window between execution interval. If you running your jobs on Lollipop + with high frequency, then it's possible, that some periods are skipped, because the device is saving battery.

enter image description here

Check out restrictions for doze mode:

  • Network access is suspended.
  • The system ignores wake locks.
  • Standard AlarmManager alarms (including setExact() and setWindow()) are deferred to the next maintenance window.
  • If you need to set alarms that fire while in Doze, use setAndAllowWhileIdle() or setExactAndAllowWhileIdle().
  • Alarms set with setAlarmClock() continue to fire normally — the system exits Doze shortly before those alarms fire.
  • The system does not perform Wi-Fi scans.
  • The system does not allow sync adapters to run.
  • The system does not allow JobScheduler to run.

But you can use some hacks to make your job executes at specific time/immediately after scheduling.

Upvotes: 4

Related Questions