无法启动服务意图 [英] Unable to start Service Intent
问题描述
我有一个服务类.我已将此类导出到 jar 并将该 jar 嵌入到我的客户端应用程序中.
I have a service class. I have exported this class to jar and I have embed the jar in my client app.
需要时,我会调用服务类.当我尝试这样做时,出现以下错误:
When needed, I call the service class. When I try to do this, I get the following error:
Unable to start service Intent {comp={com.sample.service/com.sample.service.serviceClass}} : not found
除了服务类之外,我还有其他类,我可以访问(创建该类的对象)在同一个 jar 中.
I have other class apart from the service class, which I am able to access (create object of that class) which are inside the same jar.
我觉得我在配置或清单中遗漏了一些东西.
I feel I have missed out some thing in my configuration or manifest or so.
请帮我识别相同的.我的代码如下:
Please help me identifying the same. My code is below:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent intent = new Intent () ;
intent.setClassName("com.sample.service" ,"com.sample.service.serviceClass") ;
this.startService(intent) ; // when I call this line I get the message...
// binding other process continue here
}
客户端 manifest.xml
Client manifest.xml
<service android:name="com.sample.service.serviceClass"
android:exported="true" android:label="@string/app_name"
android:process=":remote">
<intent-filter><action android:name="com.sample.service.serviceClass"></action>
</intent-filter>
</service>
提前致谢,
维奈
Thanks in advance,
Vinay
推荐答案
首先,你不需要 android:process=":remote"
,所以请移除它,因为它只会做占用额外的 RAM 没有任何好处.
First, you do not need android:process=":remote"
, so please remove it, since all it will do is take up extra RAM for no benefit.
其次,由于
元素包含一个动作字符串,请使用它:
Second, since the <service>
element contains an action string, use it:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent intent=new Intent("com.sample.service.serviceClass");
this.startService(intent);
}
这篇关于无法启动服务意图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!