Unable to start service Intent: not found

馋奶兔 提交于 2019-11-28 09:38:20
firetrap

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.

The service must be also be included in the Manifest:

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

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

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

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

     <service
        android:name="service.TimerService"
        android:exported="false" >
    </service>

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

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.

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");
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!