17

I know, I am not the first onbe with this problem, but I tried so many solutions, I have found and no one works... maybe you could find the error

The error (also came so without .class and with /.Client depending on other settings)

12-02 16:40:15.359: W/ActivityManager(74): Unable to start service Intent { act=com.android.fh.EnOceanApp.Client.class }: not found

In the manifest, this is included in application, out of activities (tried it also in activities and with ".Client"

The code in onCreate()

    startService(new Intent(this, Client.class)); 

or

 startService(new Intent(this.getApplicationContext(), Client.class));

or

Intent intent=new Intent("com.android.fh.EnOceanApp.Client.class");
    this.startService(intent);

or

  Intent intent=new Intent("com.android.fh.EnOceanApp.Client");
    this.startService(intent);

And now, I dont have an Idea anymore.... com.android.fh.EnOceanApp is the package, Client.java the service-class in this package

and the manifest I forgot:

  <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" >
        <activity
            android:label="@string/app_name"
            android:name=".EnOceanAppActivity" >
            <intent-filter >
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>      
        </activity>

      <activity android:name=".ListView" 
          android:label="List View">
      </activity> 
      <activity android:name=".GraphView" 
          android:label="Graph View">
      </activity>
      <service 
            android:name=".Client"></service> //with and without ., of course without this comment
    </application>
nico
  • 1,039
  • 4
  • 13
  • 27

8 Answers8

21

Thanks to user njzk2 for letting me notice what was happening.

I've had the same problem. It seem that Android OS can't find the service class that you've requested if you haven't registered before in the manifest file of your proyect.

Remember that a service is like an activity but without graphic interface. It means that the services needs to be registered before you can use them

This is how you register the service in your Android project:

<application>
    <!-- your code -->
    <activity>
        <!-- your code  -->
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <service android:name="com.your.own.service.class"></service>
</application>

Just Remember that YourService class needs to extend from Service, if not your class won't be a service.

public class YourService extends Service{}
JohnnyBack
  • 135
  • 1
  • 9
AXSM
  • 1,142
  • 1
  • 12
  • 27
  • 3
    Had the same problem, and noticed that if I close the tag with "/>" it doesn't detect the service after app upgrade, but if I close with "" then it detects it after app upgrade. Weeiird. – Danail Nov 17 '13 at 19:25
  • @Konstantin, think you just need to clear the entire project. That was the issue for me. – Danail Dec 02 '13 at 18:49
  • @Danail I just had to make a minor change in the Manifest, like adding a label to any service. That seemed to update the Manifest stored in my device. I could remove my change afterwards. Project > Clean could also do the trick. It happened after updating the app via Eclipse. While updating I was asked to delete the existing app due to signature mismatch. I did so. Afterwards the old Manifest probably stayed on the device but my new app required a newer Manifest. – OneWorld Dec 03 '14 at 14:51
4

Sometimes you'll need to fully qualify your class name in the manifest, rather than using the shortform (.classname). I've seen that when I used classes from a different package, but perhaps it would help here since the service intent may go outside of the app.

ProjectJourneyman
  • 3,566
  • 1
  • 27
  • 37
  • This doesn´t change anything so far :( – nico Dec 03 '11 at 12:17
  • Helped me. I had my service in a different package than my main activity – Tirtha Oct 31 '12 at 10:44
  • com.andorid.* is restricted on the Playstore (Just FYI) – scottyab Nov 13 '13 at 13:13
  • @scottyab turns out my app's package name is com.mycompany.androidapp ... so it seems it's performing some regex and the com...*android* matched and is probably causing problems? I can't change my package name now.. now what? – strangetimes Nov 25 '16 at 22:43
2

So.. just to eventually help others or not:

I made a new project, copied the sources and tried to run it: the service was found now. What was the difference, or in other words: what do I think, might give problems: the long package name or the beginning with com.android... In the new project I just chose com.enocean

nico
  • 1,039
  • 4
  • 13
  • 27
1

Despite ALL the answers in this post and many related Unable to start service Intent: not found Unable to start Service Intent , I still struggled and it took some time for me to get this going. My scenario was slightly more complicated since I'm trying to start a service in a DIFFERENT app that the one I'm calling it with. I figured it out and here are ALL the details, along with some bonus code.

MainActivity of calling intent (or whereever)

Intent intent=new Intent("com.example.core.MusicService.1234");
//Or Intent intent=new Intent("com.example.core.MusicService.TOGGLE_PLAYBACK");
PendingIntent pendingIntent = PendingIntent.getService(this, 99, intent, PendingIntent.FLAG_CANCEL_CURRENT);

Manifest: of Service (Service tag inside Application tag) It's

    <service android:name="com.example.core.MusicService">
        <intent-filter>
            <action android:name="com.example.core.MusicService1234"></action>
        </intent-filter>
        <intent-filter>
            <action android:name="com.example.core.MusicService.TOGGLE_PLAYBACK"></action>
        </intent-filter>
    </service>

MusicService.java

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    if(intent != null){
        if(intent.getAction() != null){
            if(intent.getAction().contentEquals("com.example.core.MusicService.TOGGLE_PLAYBACK")){
                //Do work here
            }
        }
    }
}

Notes

  • Service does NOT need to be started, this intent will start it
  • "com.example.core.MusicService1234" and "com.example.core.MusicService.TOGGLE_PLAYBACK" can be whatever you want it to be, but obviously needs to match the intent-filter in the service manifest with the calling intent. You can put multiple of these so you can do different actions when your service starts depending on the value from your intent
  • 99 can be whatever you want, but must be unique if you're using notifications
  • I'm not sure it's possible to call a service in a different app (like this) without using the intent-filter - if it is, someone please enlighten us. I tried and it doesn't work.

Credit to: the cumulative information from all the posts :)

Community
  • 1
  • 1
Kevin
  • 2,296
  • 21
  • 22
0

I made the silly mistake of adding the tag to a separate in the manifest.

In that case, the current application was unable to find the service defined.

Hope you skip that mistake :)

Thanks.

Otpidus
  • 489
  • 5
  • 5
0

It is stupid mistake of android

This will not work

<service
            android:name=".classname"/>

But this will work, have separate closing tag

<service
            android:name=".classname"></service>
arun-r
  • 3,104
  • 2
  • 22
  • 20
0

Well, in my case i had to clean the project. It sometimes happens when you have made a new Java class for the service in your package/project but did not build/clean the project afterwords. In my case, i just had to clean the project to get rid of the error.

kzs
  • 1,111
  • 5
  • 20
  • 35
0

If anyone sees this and has the same problem that I did, it was because I followed a guide and used context.startService() instead of context.startActivity()

JamEngulfer
  • 747
  • 4
  • 11
  • 33