使用广播接收器进行报警管理和通知(Using a broadcast receiver for alarm manager and notification)

编程入门 行业动态 更新时间:2024-10-24 22:22:18
使用广播接收器进行报警管理和通知(Using a broadcast receiver for alarm manager and notification)

我创建了一个闹钟应用程序,可在闹钟响起时播放音乐。 我也设置了通知。 我正在使用广播接收器,但是当我离开创建它并播放音乐的活动时它就会结束。 我的第一个问题是,广播接收器是处理这种情况的最佳方式,并且在清单中实现接收器是消除我丢失接收器问题的唯一方法。 当我离开创建应用程序的活动时,我收到错误,因为我没有取消注册接收器。 我的第一个应用程序,需要一些建议 如果需要,我可以提供代码。

I created an alarm clock app that plays music when the alarm goes off. I set up a notification as well. I am using a broadcast receiver but it is ended when I leave the activity that created it and plays the music. My first question is, is a broadcast receiver the best way to handle this and is implementing a receiver in the manifest the only way to eliminate my problem of losing my receiver. When I leave the activity that created the app, I receive an error because I haven't unregistered the receiver. My first app and needing some advice. I can provide the code if needed.

最满意答案

您可以使用内置警报来触发使用pendingintent。 这样你就不需要广播接收器了。

You could use the inbuilt alarm to trigger using a pendingintent. That way you don't need a broadcast receiver.

更多推荐

本文发布于:2023-07-31 01:29:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1340561.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:接收器   通知   broadcast   receiver   manager

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!