在 Android 中启动远程服务并接收结果 [英] start a remote service and receive a result in Android

查看:10
本文介绍了在 Android 中启动远程服务并接收结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个应用程序.一个应用有 Activity,另一个是后台服务.

I have two applications. One app has the Activity and another one is a background service.

我可以使用隐式意图过滤器从我的活动应用程序访问服务应用程序.

I can able to access the service app from my activity app using implicit intent filters.

我需要从服务接收结果.

I need to receive a result from the service.

例如:

从活动应用程序中,我将启动服务并发送数据.在服务应用中,我需要接收数据并进行一些检查,并需要将修改后的结果返回到活动应用.

From activity app, i am going to start the service and send a data. In the service app, i need to receive the data and do some inspections and need to return to the activity app as modified result.

我可以通过 putExtra 发送,也可以通过 getExtra 在服务中检索它.我需要从服务返回一个值并在活动应用程序中接收它.

I can able to send by putExtra and can able to retrieve it in the service by getExtra. I need to return a value from service and receive it in activity app.

PS:我需要的是,与我们对 finish()onActivityResult() 与活动结果所做的相同.

PS: The thing i needed is, the same way what we do with finish() and onActivityResult() with the Activity results.

在此先感谢各位大师...

Thanks in advance to you masters...

推荐答案

既然有一个完美的活页夹协议,你为什么要通过意图进行交流.

Why do you want to communicate through intent while there is a perfectly working binder protocol.

http://developer.android.com/guide/topics/basics/bound-services.html

如果 Activity 使用bindService()"启动服务,则该服务将一直运行,直到 Activity 调用unbindService()".

If an activity starts a service with 'bindService()' then the service will run until the activity calls 'unbindService()'.

这篇关于在 Android 中启动远程服务并接收结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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