I've read probably 100 questions and answers on this issue, but I cant seem to get this working. I'm trying to start a Service
from an Activity
. My manifest file seems OK, the way I'm starting the Service
also seems to be correct. The following error is showing up in LogCat:
ActivityManager(1296): Unable to start service Intent
{ cmp=com.exercise.AndroidClient/com.client.Communication }: not found
I'm attempting to start the service by calling this in my Activity
:
startService(new Intent(getApplicationContext(), Communication.class));
The Service
is the following:
public class Communication extends Service {
public Communication() {
super();
}
@Override
public void onCreate() {
super.onCreate();
Log.i("Service", "Created service");
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
Log.i("Service", "onStartCommand called");
return START_STICKY;
}
@Override
public IBinder onBind(Intent arg0) {
return null;
}
}
The entry in my manifest file is:
<?xml version="1.0" encoding="utf-8" ?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.exercise.AndroidClient" android:versionCode="1"
android:versionName="1.0">
<application android:icon="@drawable/sms" android:label="@string/app_name" >
<activity> ... </activity>
<service android:enabled="true" android:name=".Communication" />
</application>
</manifest>
Any advice is greatly appriciated.
You can start a service from an activity or other application component by passing an Intent to startService() or startForegroundService() . The Android system calls the service's onStartCommand() method and passes it the Intent , which specifies which service to start.
IntentService runs outside the application in a background process, so the process would run even if your application is closed.
Where is the Communication class?
In your manifest you declare a service with android:name=".Communication"
, this means that your service class should be located in com.exercise.AndroidClient.Communication
Check that the packages are correct. Note that the "." (dot) refers to the root of your package (ie the package declared in the manifest). So, for example, if your package is com.exercise.AndroidClient
and your service class is under com.exercise.AndroidClient.services.Communication
you need to declare the service like this:
<service android:enabled="true" android:name=".services.Communication" />
Or specify the full package:
<service android:enabled="true" android:name="com.exercise.AndroidClient.services.Communication" />
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With