简体   繁体   English

待处理的意图类型和警报管理器

[英]Pending Intent types and the Alarm Manager

I would like to set an alarm that will fire off once. 我想设置一个将触发一次的警报。

There is a pendingintent flag named OneShot. 有一个名为OneShot的未决意图标志。 It looks like that would be the right flag to use. 看起来这将是正确的标志。

But do I need to use that flag? 但是我需要使用该标志吗? If I use AlarmManager.SetTime(), then it should not repeat. 如果我使用AlarmManager.SetTime(),则不应重复。

What does OneShot offer? OneShot提供什么?

I think you're asking the difference between scheduling an alarm one time, via AlarmManager.set (not setTime?) and the use of PendingIntent.FLAG_ONE_SHOT . 我认为您是在询问通过AlarmManager.set (不是setTime?)安排一次警报与使用PendingIntent.FLAG_ONE_SHOT之间的区别。

First understand that a PendingIntent is a license to act as your app with your apps perms at some point in the future. 首先要了解, PendingIntent是在将来的某个时刻与您的应用程序一起充当您的应用程序的许可证。 From the PI docs: "The returned object can be handed to other applications so that they can perform the action you described on your behalf at a later time." 在PI文档中:“返回的对象可以移交给其他应用程序,以便它们以后可以执行您代表您描述的操作。”

If you just use AlarmManager.set ONCE, then yes, your PendingIntent will only be fired once, but whatever captures it can use it more than once, unless you send it with a "one shot" flag. 如果仅使用AlarmManager.set ONCE,则可以,您的PendingIntent将仅被触发一次,但是捕获到的任何东西都可以多次使用它,除非您使用“一发”标志发送它。 Now, if "whatever captures it" is also your own app, then it's probably not a big deal (you are unlikely to abuse your own future self ;)). 现在,如果“无论捕获了什么”也是您自己的应用程序,那么它可能没什么大不了的(您不太可能滥用自己的未来自我;)。 Still, if it's a PendingIntent that you think should only ever be used once, it's probably just safer to go ahead and use the one shot flag anyway. 不过,如果您认为这只是一个PendingIntent ,则应该只使用一次,但继续使用一个shot标志可能更安全。

To sum up the difference, setting FLAG_ONE_SHOT sends the permissions to use the PI only once with the PI, versus only firing it off once with AlarmManager . 综上的差异,设置FLAG_ONE_SHOT发送权限 PI只有一次使用PI,与只发射它关闭一次AlarmManager How many times you fire the alarm, and what the permissions of the PI are, are two different things. 您触发警报多少次以及PI的权限是两回事。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM