Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
517 views
in Technique[技术] by (71.8m points)

java - Android: unable to start service intent: not found?

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>
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...