40

I've the same issue described here but i can't understand whats wrong.

My issue is: Unable to start service Intent { act=.connections.MoodyService } U=0: not found

EDIT I've changed my package from connections to service in the source code, sorry for the confusion

My manifest.xml

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.moody"
android:installLocation="auto"
android:versionCode="0"
android:versionName="0.6.7 alpha" >

<uses-sdk
    android:maxSdkVersion="18"
    android:minSdkVersion="14"
    android:targetSdkVersion="17" />

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

<application
    android:allowBackup="true"
    android:allowClearUserData="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name="activities.MainActivity"
        android:label="@string/app_name" >
    </activity>
    <activity
        android:name="activities.Menu_esq"
        android:label="@string/title_activity_menu_esq" >
    </activity>
    <activity
        android:name="activities.BaseActivity"
        android:label="@string/title_activity_base" >
    </activity>
    <activity
        android:name="activities.MainView"
        android:label="@string/title_activity_main_view" >
    </activity>
    <activity
        android:name="activities.LoginActivity"
        android:label="@string/app_name"
        android:noHistory="true"
        android:windowSoftInputMode="adjustResize|stateVisible" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity
        android:name="com.example.moody.LeftActivity"
        android:label="@string/title_activity_left" >
    </activity>
    <activity
        android:name="com.example.moody.RightActivity"
        android:label="@string/title_activity_right" >
    </activity>
    <activity
        android:name="activities.UserDetailsActivity"
        android:label="@string/title_activity_user_details" >
    </activity>
    <activity
        android:name="fragments.TopicsPreview"
        android:label="@string/title_activity_copy_of_topics_preview" >
    </activity>
    <activity android:name="activities.Loading" >
    </activity>

    <service
        android:name=".service.MoodyService"
        android:icon="@drawable/ic_launcher"
        android:label="@string/moody_service" >
    </service>
</application>

service is the package and MoodyService is the class name

My service class

public class MoodyService extends Service {

public MoodyService() {
    // TODO Auto-generated constructor stub
}

private boolean isRunning = false;
Object getContent;

@Override
public IBinder onBind(Intent intent) {
    // TODO Auto-generated method stub

    return null;
}

@Override
public void onCreate() {
    super.onCreate();
}

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    super.onStartCommand(intent, flags, startId);

    // Announcement about starting
    Toast.makeText(this, "Starting the Demo Service", Toast.LENGTH_SHORT)
            .show();

    // Start a Background thread
    isRunning = true;
    Thread backgroundThread = new Thread(new BackgroundThread());
    backgroundThread.start();

    // We want this service to continue running until it is explicitly
    // stopped, so return sticky.
    return START_STICKY;
}

@Override
public void onDestroy() {
    super.onDestroy();

    // Stop the Background thread
    isRunning = false;

    // Announcement about stopping
    Toast.makeText(this, "Stopping the Demo Service", Toast.LENGTH_SHORT)
            .show();
}

private class BackgroundThread implements Runnable {
    int counter = 0;

    public void run() {
        try {
            counter = 0;
            while (isRunning) {
                System.out.println("" + counter++);
                new Contents().getAll(getResources(),
                        getApplicationContext());
                Thread.currentThread().sleep(5000);
            }

            System.out.println("Background Thread is finished.........");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

And in my main Intent.

Intent start = new Intent(".service.MoodyService");
        this.startService(start);

and also tried

Intent intent = new Intent(this, MoodyService.class);
        this.startService(intent);

and tried with the full path

<service
    android:name="com.example.moody.service.MoodyService"
    android:icon="@drawable/ic_launcher"
    android:label="@string/moody_service" >
Karthikeyan
  • 196
  • 2
  • 10
firetrap
  • 1,947
  • 3
  • 24
  • 39
  • still there is some error howcome ur error in package 'act=com.example.moody.connections.MoodyService' but u are having `"com.example.moody.service.MoodyService"' as package name – Shakeeb Ayaz Oct 01 '13 at 09:14
  • @ShakeebS i've changed for a new package and forgot to update the post – firetrap Oct 01 '13 at 09:19
  • I found this blog entry which explained the compileSdk 30 issue really well https://asvid.github.io/2021-09-03-android-service-binding-on-api30 – MikeMcC Apr 05 '22 at 18:15

8 Answers8

29

Solved

I deleted the period in the beginning of the package name in the manifest and it worked, in another words:

This doesn't work:

.yourPackage.YourClass

But this does work:

 yourPackage.YourClass

And in the main:

Intent intent = new Intent(this, MoodyService.class);
        this.startService(intent);

But it goes against what is written in the documentation:

android:name The name of the Service subclass that implements the service. This should be a fully qualified class name (such as, "com.example.project.RoomService"). However, as a shorthand, if the first character of the name is a period (for example, ".RoomService"), it is appended to the package name specified in the element. Once you publish your application, you should not change this name (unless you've set android:exported="false").

There is no default. The name must be specified.

Giacomo1968
  • 25,759
  • 11
  • 71
  • 103
firetrap
  • 1,947
  • 3
  • 24
  • 39
  • 1
    Comlpetely missed that, though it is an error on your part. When you have package="com.example.moody" in the root of your manifest and you write android:name=".service.MoodyService", then the system will look for a service called "com.example.moody.service.MoodyService". But your output at top of q says "com.example.moody.connections.MoodyService", hence a copy paste error at some time, I assume. – cYrixmorten Oct 01 '13 at 07:28
  • 1
    still there is some error howcome ur error in package 'act=com.example.moody.connections.MoodyService' but u are having `"com.example.moody.service.MoodyService"' as package name – Shakeeb Ayaz Oct 01 '13 at 09:13
  • is because i've updated the packages in the code and edited the question, but forgot to update the package name in the question – firetrap Oct 01 '13 at 09:25
  • the same happened to me when i renamed my Service class. Had to change it manually in the manifest – fersarr Mar 07 '14 at 06:57
  • In my case this been reverse. I changed in my manifest from "yourPackage.YourClass" to ".yourPackage.YourClass" and it works. I realize that "." is a very big thing :) @firetrap Thanks for suggestion :) – Yog Guru Oct 09 '15 at 06:36
  • for me it was the exact opposite – Ryhan Mar 30 '17 at 08:43
  • also using $ instead of . in the name for the sub classes may not make it works – Dasser Basyouni Jul 20 '17 at 18:56
23

The service must be also be included in the Manifest:

<service android:name="com.x.x.serviceclass"></service>
8

Make sure you have declared your service in the manifest file.

<service  
      android:name=".MyService"  
      android:enabled="true" >
</service>

and try writing getApplicationContext() instead of "this" keyword

startService(new Intent(getApplicationContext(), MoodyService.class));
Anu
  • 89
  • 1
  • 6
4

I don't know why you are using that package-like name for your service name, but why don't you use class name for starting the service?

Intent intent = new Intent(context, YourService.class);
context.startService(intent);
sam
  • 2,780
  • 1
  • 17
  • 30
  • I tried that no diference same error, what i've done:" Intent intent = new Intent(this, MoodyService.class); this.startService(intent); " and also changed to a new package but same result, it was only there because that package it's not used anymore – firetrap Oct 01 '13 at 00:55
  • This is the exact problem that I was having. AndroidManifest.xml was fine, but I was passing the intent received by the onReceive() in BroadcastReceiver. – GrandAdmiral Jun 17 '16 at 21:14
3

I think in manifest package name for service is wrong as you said your package name is connections so it should be like this

  android:name ="connections.MoodyService"

or

  android:name="com.example.moody.connections.MoodyService"

to invoke service do

  Intent intent = new Intent(this, MoodyService.class);
    this.startService(intent);
Shakeeb Ayaz
  • 6,200
  • 6
  • 45
  • 64
  • Yes you're right as i mentioned in my own answer, but the docs say: "However, as a shorthand, if the first character of the name is a period (for example, ".RoomService"), it is appended to the package name specified in the element" so i've the period because service is the package – firetrap Oct 01 '13 at 09:14
  • `connection` is package name or `service` is package name – Shakeeb Ayaz Oct 01 '13 at 09:16
  • i've updated the question, MoodyService.java was in the package - "connections", now it's in the package - "service", my error was not the package name i only forgot to update the question – firetrap Oct 01 '13 at 09:21
1

my service is in "service" package and my manifest service enrty like this;

     <service
        android:name="service.TimerService"
        android:exported="false" >
    </service>
Habil
  • 540
  • 1
  • 8
  • 20
0

Did you create an empty constructor in the service?

If not, try that.

Also uncertain if you can use the Intent like that. You could try the 'new Inten(this, MoodyService.class)' construction.

cYrixmorten
  • 7,110
  • 3
  • 25
  • 33
  • Yes i did, and also tried: Intent intent = new Intent(this, MoodyService.class); this.startService(intent); i've updated my question with the service code – firetrap Oct 01 '13 at 00:56
-4

Did you try to use the android:name that you specified in the Manifest?

Android Manifest:

<service 
             android:enabled="true" 
             android:name="UploadService" />

The call would be sth like this:

Intent intent = new Intent("UploadService");