6

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(getApplicationContext(), 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.

Shaun
  • 65
  • 2
  • 4
  • This issue was fixed by changing `startService(new Intent(getApplicationContext(), Communication.class));` to `startService(new Intent(getApplicationContext(), com.client.Communication.class));` and also making the same change in the manifest file. I thought since all files were in the same package, that this would be ok... guess not. – Shaun May 19 '11 at 02:29

3 Answers3

4

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" />
aromero
  • 25,681
  • 6
  • 57
  • 79
  • Thanks! I've managed to figure this out a little while ago. However, I am unable to answer my own question within 8 hours of posting. – Shaun May 19 '11 at 03:53
0

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

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

Arthur
  • 149
  • 8