How to check if alarm is set

后端 未结 3 1420
眼角桃花
眼角桃花 2021-02-06 05:50

I\'m trying to check if my alarm is active or not. The alarmIsSet method will return false before the alarm is set, true when the alarm is set. So far so good, however, after th

相关标签:
3条回答
  • 2021-02-06 06:02

    Easiest way is to check the values of the (date and) time in the alarm variable, if it is not the same value as when an alarm has not been set (for you to check once what that is) then it would indicate the alarm is active and at the time of the check in the program it is either a time that has passed and the alarm has sounded or it is a time that is yet to arrive and the alarm has not yet sounded or gone off. Note that the rules may permit only one alarm activation per device session before a reboot or power off or every 12 or 24 hours and that could be why the status is not cleared.

    0 讨论(0)
  • 2021-02-06 06:10

    You just have to add

    pi.cancel();
    

    after

    am.cancel(pi);
    
    0 讨论(0)
  • 2021-02-06 06:15

    After having some headaches with this stuff myself, I found out that if I somehow had created a pending intent while testing stuff, that it actually was not cleared between tests. Even killing the app didn't do it. The intent still stayed in the system and kept returning true when checking for it. I actually had to write some code to kill it before it tested right.

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