AlarmManager not working in several devices

后端 未结 14 2002
走了就别回头了
走了就别回头了 2020-11-30 18:34

My app uses AlarmManager and it has been working since 4 years ago. But I noticed it started failing in some devices.

I\'m pretty sure code is right (I\'m using Wak

相关标签:
14条回答
  • 2020-11-30 18:58

    i stopped using AlarmManager a while ago... a better and more stable alternative

    1. create a service
    2. register a BroadcastReceiver for BOOT_COMPLETED
    3. fire your service from the receiver
    4. start a new Handler inside your service that loop itself every X minutes (Android - running a method periodically using postDelayed() call)
    5. check if time to execute the task has come: now - execution time > 0 (How to find the duration of difference between two dates in java?)
    6. if so.. execute the task and stop the handler

    yes.. it's a pain..but the job get done NO MATTER WHAT

    0 讨论(0)
  • 2020-11-30 19:00

    We need to enable our app in autostart manager in app manager, some handsets like vivo v5,

    In vivo v5, We can find out this menu in iManager-->App Manager--> Auto Start Manager. Enable our app here.

    Then your alarm/ alarmmanager will trigger alarm if the app is killed or closed.

    0 讨论(0)
  • 2020-11-30 19:00

    I were looking for an answer and after several hours I found this:

    https://stackoverflow.com/a/35220476/3174791

    In resume is way to know if your app was killed by 'Protected apps' and this only works on Huawei devices. let me know if there is any solution for other devices (Samsung,Sony,Xiaomi, etc).

    0 讨论(0)
  • 2020-11-30 19:06

    Use AlarmManager for <5.0 devices, and JobScheduler for 5.0+ devices. I can't say for sure that JobScheduler will be unaffected by manufacturer shenanigans, but it would seem much less likely to me, given that Android is trying to move people away from AlarmManager and onto JobScheduler.

    EDIT: Google has come out with a first-party solution to this problem called WorkManager. It abstracts multiple scheduling frameworks and uses the most appropriate one for the device.

    0 讨论(0)
  • 2020-11-30 19:09

    most new phones nowadays are bundled with some kind of battery/power saving manager which do same thing you described. not counting duboosters and clean masters.

    I think you need to put a disclaimer or faq in your app / play store listing stating that this app needs to be put into exception of your battery manager app in order to work properly.

    0 讨论(0)
  • 2020-11-30 19:10

    The issue is Smart Manager. Samsung has a battery manager which at times disables certain apps from running in background. It tried to "resume" when going back to the app but completely disables the application or may resume every 5 mins or so (depending how Samsung has it).

    This would work on stock versions of android as there is no Samsung Manager. You can also install custom version of android which has some features to enable SM (depending on the rom).

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