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