2012-07-23 67 views
2

我试图制作一个项目,我有一个活动和一个来自不同包装的服务。我把这两个包放在一个项目中。从不同包装启动服务

我把活动:com.idris.activity,我把服务:com.idris.activity.service

我打电话从按钮的听众为MyService在MyActivity这样的:

Intent myIntent = new Intent(getApplicationContext(), MyService.class); 
       myIntent.putExtra("extraData", "somedata"); 
       startService(myIntent); 

应用程序清单

<?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
    package="idris.parental.monitor" 
    android:versionCode="1" 
    android:versionName="1.0" > 
<uses-sdk android:minSdkVersion="10" /> 
    <application 
     android:icon="@drawable/ic_launcher" 
     android:label="@string/app_name" > 
     <activity 
      android:name=".MyActivity" 
      android:label="@string/app_name" > 
      <intent-filter> 
       <action android:name="android.intent.action.MAIN" /> 
       <category android:name="android.intent.category.LAUNCHER" /> 
      </intent-filter> 
     </activity> 
     <service 
      android:name=".MyService" 
      android:enabled="true" /> 
    </application> 
</manifest> 

为MyService无法启动,什么shuld怎么办?

回答

3

在您的清单使用此:

<service 
    android:name=".service.MyService" 
    android:enabled="true" /> 

确保您在manifest文件中使用正确的package nameservice。如果MyService.java文件是在com.idris.activity.service包不是使用:

<service android:name="com.idris.activity.service.MyService" /> 
+1

不工作, 出错信息“10月7日至18日:04:06.975:W/ActivityManager(61):无法启动服务意图{cmp = idris.parental.monitor/.call.CallMonitorService(有额外)}}:找不到“ – adrasa 2012-07-23 15:54:05

+0

发布您的清单文件。 – biegleux 2012-07-23 16:03:06

+0

请再次检查,我已编辑我的帖子 – adrasa 2012-07-23 16:25:12

0

似乎乌尔根PKG的名字是包=“idris.parental.monitor”所以乌尔服务类PKG名称必须包含这些作为根路径,然后在表现u能为

指定例如

UR服务PKG服务。 即idris.parental.monitor.service

在清单.service.urservicename