如何后台服务之间的通信,后台、通信

2023-09-06 23:15:04 作者:安心将你放弃

我在执行一个应用程序,因为我有两个服务。一位做了一些工作,并通过一定的价值到另一个服务,而该服务不会使用该值的一些任务。当第一个服务产生的第一个值就应该启动第二服务。这里由第一个服务生成的值将在第二服务队列之后加入。第一次当第二个服务启动时我可以设置使用意图队列中的价值,但我不知道如何启动第二届售后服务通信。到服务这些之间如何进行通信。

I am implementing an app, in that I have two Services. One does some task and pass some value to another service and that service does some task using this value. When the first Service generate first value it should start 2nd service. Here after the values generated by the first service will be added in a queue in 2nd service. First time when the 2nd service starts I can set the value in queue using intent, but I don't know how to communicate after starting the 2nd service. How to communicate between these to services.

任何人有一些想法在此请大家帮帮我。

Anybody have some idea on this please do help me.

推荐答案

由于我的理解,你可以沟通有两种方式:

As of my understanding, you may communicate in two ways:

绑定 您的服务(S) 请使用 的BroadcastReceiver 您的服务(S)内交换数据/指令 Bind your service(s) make use of BroadcastReceiver within your service(s) to exchange data/commands

不过,我建议你不要被涉及多个服务的复杂设计。事实上,你应该决定是你真的需要一个普通的服务还是可以通过完成 IntentService

However, I would suggest you not to complicate your design by involving multiple services. In fact, you should decide either you really need an ordinary service or can it be done via IntentService.