3

I want to update my app to Android 6 and i use the alarmanager to shedule my background service. For my service it is important to be woken up in a approximatly hour long window. It must wake up in that window so not once the device exits doze, but i dont care when it wakes up in the window.

I use .setWindow at the moment to set my alarm. What do I have to use when I want it to work with doze mode? There is no setWindowAndallowWhileIdle

And as far as I know, setting a window instead of a fixed time should be preferred especially while in doze mode

Ben
  • 199
  • 1
  • 13

1 Answers1

1

It looks like Android has finally decided to be strict about battery optimizations and hence it is difficult to bypass doze mode. The whole point is that you really shouldn't be doing any work on a device that has been stationary for hours and rather wait until a maintenance window (where jobs will start) or the user picks up their device.

For doing inexact or periodic work which, please explore JobScheduler: that's literally what it is built for and offers you good variety in terms of scheduling [based on criteria like periodicity, metered/ unmetered network, charging etc].

They don't want us to do any work at all while dozing. So from what I can think of, your use-case of "once every hour" is only on best promise from now on. Schedule and 'hope'. Having said that, Android N has a more 'practical' (lenient) version of the doze mode where maintenance windows are quicker. You could test, my feeling is that it's not as gloomy as it sounds. The policy is fair: if a user shows the intent of interacting with the phone, they would trigger jobs.

ref https://www.bignerdranch.com/blog/diving-into-doze-mode-for-developers/

Rajat Sharma
  • 502
  • 4
  • 8
  • 17
  • The whole point of my application is to log data while the user is not interacting with the device. So i need to wake up the device in doze mode. so i think its just bad that i have to set an exact alarm to ensure its happening in my window instead of just setting a window and giving the system way more possibilities to batch the alarms. – Ben Mar 20 '17 at 10:56
  • yes you are right, setting exact alarms [which are anyway not exact after 19] instead of window looks like the way to go for you. "The whole point of my application is to log data while the user is not interacting with the device" - that is what android doesn't want anymore. Their argument is that battery drain should not happen on idly kept devices. Since the user has not been using the same. – Rajat Sharma Mar 20 '17 at 13:22