如何做一个服务返回的结果为一个活动 [英] how does a service return result to an activity

查看:120
本文介绍了如何做一个服务返回的结果为一个活动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我似乎有一个经典的任务,但我无法找到如何做到这一点的任何例子。

i seem to have a classic task, yet i can't find any examples on how to do it.

我要下载的东西。以及我调用Web服务,并得到回应...但它pretty的大致相同。

i want to download something. well i call a web service and get a response... but its pretty much the same.

为了做到这一点,我有启动的产生一个线程来完成这一工作服务的活动。

in order to do this i have an activity that starts a service that spawns a thread that does the job.

现在我想用我在开始的服务活动得到了数据。

now i would like to use the data i got in the activity that started the service.

(我假设开始另一项活动,以处理显示的结果将是简单的工作)

(i assume that starting another activity to handle the job of displaying the result would be simple)

我的问题是如何服务的通知活动的东西(启动它或者另外一个的)。

my problem is how does the service notify an activity (the one that started it or another one) of something.

任何指针的例子是很多AP preciated。

any pointers to examples are much appreciated.

关于

推荐答案

发送广播意图通过sendBroadcast()的数据,该活动挑选了一个BroadcastReceiver。

Send a broadcast Intent with the data via sendBroadcast(), that the activity picks up with a BroadcastReceiver.

下面是一个例子: https://github.com/ commonsguy / CW-的Andr​​oid /树/主/服务/ WeatherAPI 文档: http://developer.android.com/reference/android/content/BroadcastReceiver.html

Here's an example of that: https://github.com/commonsguy/cw-android/tree/master/Service/WeatherAPI Doc: http://developer.android.com/reference/android/content/BroadcastReceiver.html

这篇关于如何做一个服务返回的结果为一个活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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