当一项服务正在运行时,是否可以仅向该服务发送 Intent ?
我知道函数 startService()
和 onStartCommand()
但我不想“启动”服务,在我的情况下它已经启动了。 p>
所以我想知道是否可以仅针对一个广播接收器,或者它是否退出其他内容以仅发送到一个服务/Activity ?
在 sendBroadcast(intent)
之前我对 intent.setClass()
的尝试没有得出结果。
最佳答案
I'm aware of the functions startService() and onStartCommand() but I don't want "start" the service, in my case it was already started.
startService()
仅通过 onStartCommand()
将消息传递给现有正在运行的服务副本(如果存在这样的副本)。如果没有正在运行的服务副本,它将创建这样的副本(从而触发对 onCreate()
的调用)。
So I would like to know if it is possible to target only one brodcast receiver or if it exits something else to send only to one service/activity?
请使用startService()
。
关于android - 仅向一项服务发送 Intent ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11136922/