简体   繁体   English

广播接收器被视为服务吗?

[英]Is broadcastreceiver considered a service?

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. 1,我通过扩展broadcastreceiver开发了SMS应用程序,并且一切正常,问题是电话休眠了一会儿之后-该应用程序不再起作用。 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. (它将在Android闲置X分钟后被Android杀死)....因为我没有“ START_REDELIVER_INTENT”(就像我在服务中一样)....而且我读了一些帖子说使用AlarmManaget-但我不明白为什么。 ( 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 ....) 如果我需要在android将其杀死后使用服务来运行自身-我不知道如何将我的broadcastreceiver转换为服务...(因为这是唯一需要运行的东西...其他一切都是只是设置和偏好设置....)

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 ? 2,例如,当我安装GOSMS时,android会问我-从现在开始,我要使用哪个应用程序作为默认SMS程序,我需要编写什么代码才能向终端用户发出这种通知? right now my application only receive SMS notifications ... doesn't send anything ... 现在我的应用程序仅接收短信通知...不发送任何信息...

Thanks in advance.... 提前致谢....

So is broadcastreceiver considered a Service ? 那么广播接收器被认为是服务吗?

No, that's why it's called BroadcastReceiver and not Service . 不,这就是为什么它被称为BroadcastReceiver而不是Service

Please see Application Fundamentals to properly understand the various key components of an Android application. 请参阅“ 应用程序基础知识”以正确了解Android应用程序的各种关键组件。

Also, if you have correctly registered your BroadcastReceiver's <intent-filter> in your AndroidManifest.xml then it will be 'woken up' to process Intents although as Jens mentions that may require you acquiring a WakeLock of some sort (and correctly acquiring/handling/releasing various resources during/after your task is accomplished). 另外,如果您已在AndroidManifest.xml正确注册了BroadcastReceiver's <intent-filter> ,则它将被“唤醒”以处理Intents尽管正如Jens所述,这可能需要您获取某种WakeLock (并正确地获取/处理) /在完成任务期间/之后释放各种资源)。

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

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