2

I've observed strange behaviour on some Samsung devices (Galaxy A5 maybe others)

setExactAndAllowWhileIdle() for times bigger than 15 minutes is shifted approximately 3 minutes

The alarm is set on lets say 10.20, I can do it in debug mode so I see it is ok, and when device is asleep it triggers on 10.23

This behaviour does not appear when device is plug in.

It has been tested on many other devices (LG, OnePlus, Xiaomi) and there were no such problems.

Samsung Battery saver is turned of for my app.

Is there any way to avoid such shifting on Samsung devices ?

It looks like not the it is not delaying the alarm when it sleep, but adding time when using metod setExactAndAllowWhileIdle, because alarms setted during sleep mode are shifted as well when device is waked up

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
wojciech_maciejewski
  • 1,277
  • 1
  • 12
  • 28
  • This is normal behaviour and there isn't much that you can do about it. It doesn't appear when the device is plugged in (or when the screen is ON) because the device cannot enter doze under those conditions. But while Doze is active, delays of up to 9 minutes can occur before the doze maintenance window opens under typical conditions. – Elletlar Jul 26 '18 at 11:22
  • 2
    It is not a normal behaviour, normal behaviour is that you can't trigger alarm more offen than 9 minutes, not that it can be shifted when you use setExactWhileIdle, and not only on some specific devices – wojciech_maciejewski Jul 26 '18 at 13:06
  • What do you mean it cannot be shifted? Have you read the documentation for setExactAndAllowWhileIdle()? It doesn't seem like you understand how that method works as it relates to the doze maintenance window. The fact that Alarm fires differently on different devices doesn't mean much because the implementation of the alarm manager has changed markedly for different versions of Android. – Elletlar Jul 26 '18 at 13:30
  • More specifically, research what the "AllowWhileIdle" means in "setExactAndAllowWhileIdle"... – Elletlar Jul 26 '18 at 13:33
  • from documentation 'To help with scheduling alarms, Android 6.0 (API level 23) introduces two new AlarmManager methods: setAndAllowWhileIdle() and setExactAndAllowWhileIdle(). With these methods, you can set alarms that will fire even if the device is in Doze.' I don't need to understand more, your wrong between what is allowed during doze mode and what is not. AllowWhileIdle works without respection of doze mode (so it will triggers even if app is in doze mode, not waiting for maintenance window like setExact and setWindow) ,but not more often than 9 minutes – wojciech_maciejewski Jul 26 '18 at 13:59
  • That is correct, they can still fire, but only during doze maintenance windows. I think the best way to think about this oddly named function is that it is "Exact" when the screen is ON or the device is charging, but it is inexact when the device is dozing. [Power Managment](https://source.android.com/devices/tech/power/mgmt) – Elletlar Jul 26 '18 at 14:03
  • 3
    You are still not right. If you read this -> https://developer.android.com/training/monitoring-device-state/doze-standby#restrictions you will know that alarms set by setExact and setWindow and all others waits for maintenance window. not those with AllowWhileIdle which were specifically created to avoid doze. Problem is why samsung shifts those alarms always with the same time ( it is always 3 minutes with few seconds) – wojciech_maciejewski Jul 26 '18 at 14:08
  • here you have another example from documentation about behaviour of allowWhileIdle https://developer.android.com/training/scheduling/alarms#doze-and-standby – wojciech_maciejewski Jul 26 '18 at 14:10
  • Okay, but if I am wrong why do your alarms not fire on time? And do think Google would design Doze so that a single app could prevent it? [setExactAndAllowWhileIdle - is not exact](https://stackoverflow.com/questions/33110246/setexactandallowwhileidle-is-not-exact-as-of-developer-reference). Read the comment from Android author Mark Murphy [CommonsWare]. But the only API in AlarmManager that functions as you imagine is setAlarmClock. – Elletlar Jul 26 '18 at 14:17
  • Also, please be aware that if you're testing Android 6 and 7 devices the behaviour is totally different. On 6, it takes about an hour for doze to come after the screen is turned OFF. On 7, it comes on almost immediately. But this has nothing to do with Samsung specifically. – Elletlar Jul 26 '18 at 14:19
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/176807/discussion-between-wojciech-maciejewski-and-elletlar). – wojciech_maciejewski Jul 26 '18 at 14:19
  • Possible duplicate of [setExactAndAllowWhileIdle - is not exact as of developer reference](https://stackoverflow.com/questions/33110246/setexactandallowwhileidle-is-not-exact-as-of-developer-reference) – Vadim Kotov Oct 31 '19 at 12:06
  • I have exprienced same problem on my samsung phone which run on oreo. Can you find a solution to your problem? – mozer Mar 18 '20 at 08:18
  • 1
    I have used setAlarmClock. There is no other option :/ – wojciech_maciejewski Mar 18 '20 at 09:26
  • I know the question is specifically about Samsung, so this might not help, but I ran into something like this with a Google Pixel 7 pro and I posted a reply to a similar question at https://stackoverflow.com/a/74997607/1889018 – ciobi Jan 03 '23 at 21:05

0 Answers0