从一个BroadcastReceiver驾驶服务API [英] Driving a service API from a BroadcastReceiver
问题描述
我得到一个错误信息,当我尝试之前,我开的是定制的API就可以从接收器的的onReceive()绑定到本地服务。
IntentReceiver组件不允许结合服务
这是从一个服务,同时在广播reciever
获得一个数据片的最佳方式非常感谢。
P.S。我需要得到答案同步,即我有等待从服务的回答让回调可能是不可能的。
这是从一个服务,同时在广播reciever
获得一个数据片的最佳方式
块引用>如果在
广播接收器
从别的东西产生(例如,一个活动),并设置了registerReceiver()
,那么别的东西是什么应该被绑定到服务,做的工作。如果在
广播接收器
在清单中注册的组件,那么你需要重新考虑你的方法到任何问题,你正在试图解决的问题。这些类型的BroadcastReceivers的
不能绑定到服务,不能花太多时间在做的工作。如果广播接收器
不能做的工作,在不到,也就是说,10毫秒,它应该通过委派控制到服务startService()
。然后,该服务可以做一个后台线程的工作。
P.S。我需要得到答案同步,即我有等待答案从服务
块引用>见上文。
I get an error message when I attempt to bind from the onReceive() of a receiver to a local service before I drive a bespoke API on it.
"IntentReceiver components are not allowed to bind to services"
What is the best way of getting a piece of data from a service while in a broadcast reciever.
Many thanks.
P.S. I need to get the answer synchronously i.e. I have wait on the answer from the service so a callback may not be possible.
解决方案What is the best way of getting a piece of data from a service while in a broadcast reciever.
If the
BroadcastReceiver
is created from something else (e.g., an activity) and set up withregisterReceiver()
, then the "something else" is what should be binding to the service and doing the work.If the
BroadcastReceiver
is a component registered in the manifest, then you need to rethink your approach to whatever problem you are trying to solve. These sorts ofBroadcastReceivers
cannot bind to services and cannot spend much time doing work. If theBroadcastReceiver
cannot do its work in less than, say, 10ms, it should delegate control to a service viastartService()
. That service can then do the work on a background thread.P.S. I need to get the answer synchronously i.e. I have wait on the answer from the service
See above.
这篇关于从一个BroadcastReceiver驾驶服务API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!