广播接收器被视为服务吗?
我正在挖掘这个论坛,但找不到我的问题的答案....
1,我通过扩展广播接收器开发了短信应用程序,一切都运行良好,问题是手机休眠一段时间后 - 应用程序是不再工作了。那么broadcastreceiver被认为是一个服务吗? (它会在闲置X分钟后被Android杀死)....因为我没有像我在服务中那样的“START_REDELIVER_INTENT”....并且我读了一些帖子说要使用AlarmManaget - 但我不明白为什么。 (示例帖子不是关于接收短信的……而是关于日历等……)
底线 - 我该如何解决这个问题?如果我需要使用一个服务在 android 杀死它后自行运行 - 我不明白如何将我的广播接收器转换为服务......(因为它是唯一需要运行的东西......其他一切都是只是设置和首选项....)
2,例如,当我安装 GOSMS 时,Android 会问我 - 从现在开始我想使用哪个应用程序作为我的默认短信程序,我需要编写什么代码才能实现向最终用户发出此类通知?现在我的应用程序只接收短信通知...不发送任何内容...
提前致谢...
I was digging this forum but couldn't find an answer to my questions ....
1, I developed SMS application by extending broadcastreceiver and everything is working great, the problem is that after the phone is sleeping for a while - the application is no longer working. So is broadcastreceiver considered a Service ? ( that will be killed by the Android after it's been idled for X minutes ).... because I don't have the "START_REDELIVER_INTENT" like I have inside a Service .... and I read some posts that said to use the AlarmManaget - but I don't understand why. ( the examples posts were not about receiving SMS though ... were in regards to calendars etc ... )
Bottom line - how do I fix this ? if I need to use a service to run itself after the android kills it - I don't understand how to convert my broadcastreceiver to be a service... ( because it's the only thing that needs to be running ... everything else is just settings and preferences ....)
2, When I install GOSMS for example, the android ask me - from now on which app would I like to work with as my default SMS program, what to I need to code in order to achieve this kind of notification to the end-users ? right now my application only receive SMS notifications ... doesn't send anything ...
Thanks in advance....
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不,这就是为什么它被称为
BroadcastReceiver
而不是Service
。请参阅应用程序基础知识以正确理解 Android 应用程序的各个关键组件。
另外,如果您在
AndroidManifest.xml
中正确注册了BroadcastReceiver's
,那么它将被“唤醒”处理Intents
,尽管正如Jens提到的,这可能需要您获取某种WakeLock
(并在任务完成期间/之后正确获取/处理/释放各种资源)。No, that's why it's called
BroadcastReceiver
and notService
.Please see Application Fundamentals to properly understand the various key components of an Android application.
Also, if you have correctly registered your
BroadcastReceiver's
<intent-filter>
in yourAndroidManifest.xml
then it will be 'woken up' to processIntents
although as Jens mentions that may require you acquiring aWakeLock
of some sort (and correctly acquiring/handling/releasing various resources during/after your task is accomplished).