AlarmManager not working properly

后端 未结 2 1296
傲寒
傲寒 2021-01-05 01:48

I\'m trying to create an alarm based application. I\'m using AlarmManager. The thing is that it\'s not reliable at all. In some devices it works.. in other devi

相关标签:
2条回答
  • 2021-01-05 02:27

    In addition to marcin´s answer, another reason could be a build in task-manager/energy-manager. If you write, your alarm works fine on some devices and in some not, it could be because of lower/higher APIs like Marcin suggested. But there is another thing that I have explored on my Huawei Ascend Mate 7: Some devices have an energy control system inside that directly closes the application completely after screen goes off. I had the same problem with one of my apps with an alarm manager and nothing helped, wether a usual service nor a foreground service nor any other programming solution. It was just simple: I had to go to settings-->energy saving mode-->protected apps. Here you have to enable the protection of your app.

    It may be that this is not the solution in Your case, but it is in much other devices and this explanation is too long for a comment, so I have to put it as answer.

    0 讨论(0)
  • 2021-01-05 02:50

    There's change in how AlarmManager works made in API19. So I assume it "works" on pre API19 but does "not work" on newer devices. Here's why:

    Note: Beginning with API 19 (KITKAT) alarm delivery is inexact: the OS will shift alarms in order to minimize wakeups and battery use. There are new APIs to support applications which need strict delivery guarantees; see setWindow(int, long, long, PendingIntent) and setExact(int, long, PendingIntent). Applications whose targetSdkVersion is earlier than API 19 will continue to see the previous behavior in which all alarms are delivered exactly when requested.

    0 讨论(0)
提交回复
热议问题