AlarmManager not working in several devices

后端 未结 14 2050
走了就别回头了
走了就别回头了 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

提交回复
热议问题