从一个BroadcastReceiver驾驶服务API [英] Driving a service API from a BroadcastReceiver

查看:115
本文介绍了从一个BroadcastReceiver驾驶服务API的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我得到一个错误信息,当我尝试之前,我开的是定制的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 with registerReceiver(), 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 of BroadcastReceivers cannot bind to services and cannot spend much time doing work. If the BroadcastReceiver cannot do its work in less than, say, 10ms, it should delegate control to a service via startService(). 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆