如何后台服务之间的通信, [英] How to communicate between background services

查看:101
本文介绍了如何后台服务之间的通信,的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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:

  1. 绑定 您的服务(S)
  2. 请使用 的BroadcastReceiver 您的服务(S)内交换数据/指令
  1. Bind your service(s)
  2. 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.

这篇关于如何后台服务之间的通信,的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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