Failed to start service

I have a class of service. I have exported this class to jar, and I am embedding jar in my client application.

If necessary, I call the service class. When I try to do this, I get the following error:

Unable to start service Intent {comp={com.sample.service/com.sample.service.serviceClass}} : not found 

I have another class, besides the service class that I can get (create an object of this class), which is inside the same jar.

I feel like I missed something in my configuration or manifests or so.

Please help me identify the same. My code is below:

 public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Intent intent = new Intent () ; intent.setClassName("com.sample.service" ,"com.sample.service.serviceClass") ; this.startService(intent) ; // when I call this line I get the message... // binding other process continue here } 

Manifest.xml client

 <service android:name="com.sample.service.serviceClass" android:exported="true" android:label="@string/app_name" android:process=":remote"> <intent-filter><action android:name="com.sample.service.serviceClass"></action> </intent-filter> </service> 

Thanks in advance,
Blame it

+78
android android-intent service intentfilter
Aug 09 '10 at 11:02
source share
6 answers

Firstly, you do not need android:process=":remote" , so please delete it, since all it does is take extra RAM without any benefits.

Secondly, since the <service> element contains an action string, use it:

 public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Intent intent=new Intent("com.sample.service.serviceClass"); this.startService(intent); } 
+48
Aug 09 '10 at 12:10
source share
โ€” -

For someone else who came across this problem, I had this problem and pulled my hair out. I had an OUTSIDE service declaration from <application> 'end tag DUH!

RIGHT:

 <manifest xmlns:android="http://schemas.android.com/apk/res/android" ...> ... <application android:icon="@drawable/icon" android:label="@string/app_name"> <activity ...> ... </activity> <service android:name=".Service"/> <receiver android:name=".Receiver"> <intent-filter> ... </intent-filter> </receiver> </application> <uses-permission android:name="..." /> 

WRONG, but still compiles without errors:

 <manifest xmlns:android="http://schemas.android.com/apk/res/android" ...> ... <application android:icon="@drawable/icon" android:label="@string/app_name"> <activity ...> ... </activity> </application> <service android:name=".Service"/> <receiver android:name=".Receiver"> <intent-filter> ... </intent-filter> </receiver> <uses-permission android:name="..." /> 

+70
Mar 25 '11 at 23:26
source share

1) verify that the service declaration in the manifest is nested in the application tag

 <application> <service android:name="" /> </application> 

2) check if your service.java in the same package or diff package as an action

 <application> <!-- service.java exists in diff package --> <service android:name="com.package.helper.service" /> </application> 
 <application> <!-- service.java exists in same package --> <service android:name=".service" /> </application> 
+31
May 6 '11 at 4:22
source share

I hope I can also help someone with this information: I moved the service class to another package and I fixed the links. The project was beautiful, but the service class could not be detected as a result of activity.

Observing the logcat log, I noticed a warning about the problem: activity could not find the service class, but it was strange that the package was incorrect, it contained an "/" char. The compiler was looking for

com.something./service.MyService

instead

com.something.service.MyService

I moved the service class from the package and returned, and everything worked fine.

+4
Jul 10 2018-12-12T00:
source share

I found the same problem. I lost almost one day trying to start the service from the OnClickListener method - outside of onCreate and after 1 day I still couldnโ€™t !!!! Very frustrating! I looked at an example RemoteServiceController sample. Their work, but my implementation does not work!

The only way that worked for me was from within onCreate . None of the other options worked, and believe me, I tried all of them.

Output:

  • If you put your class of service in a package other than mainActivity, I will get all kinds of errors.
  • In addition, "/" could not find the path to the service, tried to start with Intent(package,className) and nothing, as well as another type of Intent startup

  • I moved the service class to the same action package. Final form that works

  • Hope this helps someone define onClick onClick inside the onCreate method as follows:

     public void onCreate() { //some code...... Button btnStartSrv = (Button)findViewById(R.id.btnStartService); Button btnStopSrv = (Button)findViewById(R.id.btnStopService); btnStartSrv.setOnClickListener(new OnClickListener() { public void onClick(View v) { startService(new Intent("RM_SRV_AIDL")); } }); btnStopSrv.setOnClickListener(new OnClickListener() { public void onClick(View v) { stopService(new Intent("RM_SRV_AIDL")); } }); } // end onCreate 

Also very important for the manifest file, make sure the service is a child of the application:

 <application ... > <activity ... > ... </activity> <service android:name="com.mainActivity.MyRemoteGPSService" android:label="GPSService" android:process=":remote"> <intent-filter> <action android:name="RM_SRV_AIDL" /> </intent-filter> </service> </application> 
0
Feb 18 '14 at 23:10
source share

In my case, the maximum size is 1 MB for transmitting Intent data. I just use cache or storage.

0
Dec 15 '16 at 2:09
source share



All Articles