Android-绑定到其他应用程序的服务 [英] Android - Bind to a service from an other app

查看:306
本文介绍了Android-绑定到其他应用程序的服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了2份申请书. MyServiceApplicationMyActivityApplication. 在启动时,我启动MyService作为远程服务运行.我希望MyActivityApplication与之通信,但是MyActivityApplication无权访问MyServiceApplication类.我在网上看到的所有示例都通过以下方式将活动绑定到服务:

I have written 2 applications. MyServiceApplication and MyActivityApplication. On boot I launch MyService which runs as a remote service. I want MyActivityApplication to communicate with it however MyActivityApplication does not have access to MyServiceApplication classes. All the examples I see online band an activity to a service in the following way:

bindService(new Intent(Binding.this, MyService.class), mConnection, Context.BIND_AUTO_CREATE);

我的应用程序需要与MyService通信.该代码基于Google的MessengerService示例.

My Application needs to communicate with MyService. The code is based off Google's MessengerService example.

我前面提到的问题是我要绑定到的服务是由另一个应用程序启动的,该应用程序的唯一目的是启动此服务.

The trouble as I mentioned earlier is that the service I'm trying to bind to was started by an other application whose sole purpose is to start this service.

有没有一种方法可以使两个应用程序保持独立?我的想法是,我将拥有第二,第三和第四应用程序,它们都可以与同一服务通信.

Is there a way to do this where I can keep both applications independent? The idea is that I will have a second, third and fourth application all of whom may communicate with the same service.

推荐答案

您应该在服务和应用程序之间拥有一个共享库,该共享库定义用于与绑定服务进行通信的接口.

You should have a shared library between your service and application that defines the interface you use to communicate with the bound service.

这篇关于Android-绑定到其他应用程序的服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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