图书馆中的Android服务 [英] Android service in library

查看:28
本文介绍了图书馆中的Android服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个带有服务的库,我希望能够在多个 apk 中绑定到该服务.

i created a library with a service in that i want to be able to bind to in more than one apk.

这是在我的图书馆清单中

This is in my libraries manifest

<service class=".service.MyService" android:permission="com.wissen.permission.MY_SERVICE_PERMISSION">
<intent-filter>
<action android:value="com.wissen.testApp.service.MY_SERVICE" />
</intent-filter>
</service>

这是在我的 apk 清单中

and this is in my apk manifest

<uses-permission android:name="com.wissen.permission.MY_SERVICE_PERMISSION"></uses-permission>

我当然将 lib 添加到 apk 中.我一直找不到服务(警告).我做错了什么.

and i of course added the lib to the apk. i keep on getting service not found (warning). What am i doing wrong.

我是这样绑定的

bindService(new Intent("com.wissen.testApp.service.MY_SERVICE"), conn, Context.BIND_AUTO_CREATE);

解决方案:
我为这些创建了 aidl,现在它工作正常.

Solution:
I created aidl for these and its working fine now.

推荐答案

您的服务必须是远程服务.您应该创建一个 *.aidl(到您的服务的接口)并在它自己的进程中启动它.您可以在此处阅读:Android 界面定义语言 (AIDL)

Your service must be a remote service. You should create an *.aidl (interface to your service) and start it in it's own process. You can read about it here: Android Interface Definition Language (AIDL)

这篇关于图书馆中的Android服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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