Android: unable to start service intent: not found

2019-01-25 04:51发布

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>

8条回答
萌系小妹纸
2楼-- · 2019-01-25 05:24

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.

查看更多
Viruses.
3楼-- · 2019-01-25 05:35

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{}
查看更多
看我几分像从前
4楼-- · 2019-01-25 05:39

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

查看更多
我欲成王,谁敢阻挡
5楼-- · 2019-01-25 05:39

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.

查看更多
爱情/是我丢掉的垃圾
6楼-- · 2019-01-25 05:39

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()

查看更多
迷人小祖宗
7楼-- · 2019-01-25 05:40

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.

查看更多
登录 后发表回答