gpt4 book ai didi

android - 从 BroadcastReceiver 驱动服务 API

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:16:00 26 4
gpt4 key购买 nike

当我在驱动定制 API 之前尝试从接收器的 onReceive() 绑定(bind)到本地服务时,我收到一条错误消息。

“IntentReceiver 组件不允许绑定(bind)到服务”

在广播接收器中从服务获取数据的最佳方式是什么。

非常感谢。

附言我需要同步获得答案,即我等待服务的答案,因此可能无法进行回调。

最佳答案

What is the best way of getting a piece of data from a service while in a broadcast reciever.

如果 BroadcastReceiver 是从其他东西(例如,一个 Activity )创建的并使用 registerReceiver() 设置,那么“其他东西”应该是绑定(bind)的服务和工作。

如果 BroadcastReceiver 是在 list 中注册的组件,那么您需要重新考虑您尝试解决的任何问题的方法。这些类型的 BroadcastReceivers 不能绑定(bind)到服务,也不能花很多时间做工作。如果 BroadcastReceiver 不能在小于 10 毫秒的时间内完成工作,它应该通过 startService() 将控制委托(delegate)给服务。然后该服务可以在后台线程上完成工作。

P.S. I need to get the answer synchronously i.e. I have wait on the answer from the service

见上文。

关于android - 从 BroadcastReceiver 驱动服务 API,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4946729/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com