· android

Learning Android: 'Unable to start service Intent not found'

In the Android application that I’ve been playing around with I wrote a service which consumes the Twitter streaming API which I trigger from the app’s main activity like so:

public class MyActivity extends Activity {
    public void onCreate(Bundle savedInstanceState) {

        Intent intent = new Intent(this, TweetService.class);

Where TweetService is defined roughly like this:

public class TweetService extends IntentService {
    protected void onHandleIntent(Intent intent) {
      // Twitter streaming API stuff goes here

Unfortunately when I tried to deploy the app the service wasn’t starting and I got this message in the log:

01-01 03:10:31.758: WARN/ActivityManager(106): Unable to start service Intent { cmp=com.example/.TweetService }: not found

What I hadn’t realised is that the service needs to be specified in the AndroidManifest.xml file but not inside the activity definition:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example" android:versionCode="1" android:versionName="1.0">
    <application android:label="@string/app_name">
        <activity android:name="MyActivity" android:label="@string/app_name" android:launchMode="singleInstance">
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
        <service android:name="TweetService"></service>
    <uses-permission android:name="android.permission.INTERNET"/>

After adding the service definition it works fine.

  • LinkedIn
  • Tumblr
  • Reddit
  • Google+
  • Pinterest
  • Pocket