开发者

Unable to start service Intent

I've read probably 100 questions and answers on this issue, but I cant seem to get this working. I'm trying to start a Service from an Activity. My manifest file seems OK, the way I'm starting the Service also seems to be correct. The following error is showing up in LogCat:

ActivityManager(1296): Unable to start service Intent
{ cmp=com.exercise.AndroidClient/com.client.Communication }: not found

I'm attempting to start the service by calling this in my Activity:

startService(new Intent(getApplication开发者_开发百科Context(), Communication.class));

The Service is the following:

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;
    }
}

The entry in my manifest file is:

<?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>

Any advice is greatly appriciated.


Where is the Communication class?

In your manifest you declare a service with android:name=".Communication", this means that your service class should be located in com.exercise.AndroidClient.Communication

Check that the packages are correct. Note that the "." (dot) refers to the root of your package (ie the package declared in the manifest). So, for example, if your package is com.exercise.AndroidClient and your service class is under com.exercise.AndroidClient.services.Communication you need to declare the service like this:

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

Or specify the full package:

<service android:enabled="true" android:name="com.exercise.AndroidClient.services.Communication" />


I had the same error and the cause was, that the service was not defined in the AndroidManifest.xml.


Also, if your service happens to exist in a library project that you are refering to, check your project.properties file.

You have to add this line:

manifestmerger.enabled=true
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜