触发和取消 AlarmManager 的活动
我正在尝试开发一个应用程序,它可以锁定 Activity
并启动一个服务,该服务将 AlarmManager
设置为另一个 setRepeating()
触发器Service
将发送包含手机位置的短信。
我已经实现了短信的定时发送。但是,我现在想在 finish()
锁定活动时取消 AlarmManager
。请帮助我,因为我似乎无法理解解决此问题的方法。
程序流程: 锁屏(活动触发服务)--> AlarmManager(在服务类中)-->协调(发送短信的另一项服务)
I am trying to develop an app where it locks down the Activity
and starts a service which will set an AlarmManager
to setRepeating()
trigger to another Service
which will send a SMS containing the phone's location.
I have achieved the periodic sending of the SMS. However, I now want to cancel the AlarmManager
when I finish()
the lockdown activity. Please help me as I cant seem to understand the approach to address this.
Program flow:
Lockscreen (Activity trigger Service) --> AlarmManager (in Service class) --> Coordinate (Another Service that send sms)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用与您最初用于注册警报的等效的
PendingIntent
调用AlarmManager
上的cancel()
。我所说的“等效”是指它是相同类型的PendingIntent
(活动、服务、广播),并且包装了一个在所有路由元素(组件、组件、数据、MIME 类型、类别)。Call
cancel()
onAlarmManager
with an equivalentPendingIntent
to the one you used to register the alarm in the first place. By "equivalent" I mean that it is the same type ofPendingIntent
(activity, service, broadcast) and wraps anIntent
that is the same on all routing elements (component, data, MIME type, categories).