我读过大概100个问题和对这个问题的答案,但我似乎无法得到这个工作。我正尝试从Activity
开始Service
。我的清单文件似乎确定,我开始Service
的方式似乎也是正确的。下面的错误是没有显示在logcat中:无法启动服务意图
ActivityManager(1296): Unable to start service Intent
{ cmp=com.exercise.AndroidClient/com.client.Communication }: not found
我试图启动该服务由我Activity
调用此:
startService(new Intent(getApplicationContext(), Communication.class));
的Service
如下:
public class Communication extends Service {
public Communication() {
super();
}
@Override
public void onCreate() {
super.onCreate();
Log.i("Service", "Created service");
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
Log.i("Service", "onStartCommand called");
return START_STICKY;
}
@Override
public IBinder onBind(Intent arg0) {
return null;
}
}
在我的清单文件中的条目是:
<?xml version="1.0" encoding="utf-8" ?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.exercise.AndroidClient" android:versionCode="1"
android:versionName="1.0">
<application android:icon="@drawable/sms" android:label="@string/app_name" >
<activity> ... </activity>
<service android:enabled="true" android:name=".Communication" />
</application>
</manifest>
任何建议是非常appriciated。
这个问题是固定的,通过改变 'startService(新的意向书(getApplicationContext(),Communication.class));' 到 'startService(新的意图(getApplicationContext(),com.client.Communication.class));' 并且也在清单文件中进行相同的更改。我想因为所有的文件都在同一个软件包中,所以这可能会好起来......不要猜测。 – Shaun 2011-05-19 02:29:23