Reputation: 9604
all tutorials tell me to do this:
startService(new Intent(this, MyService.class));
but there is no constructor that takes Activity, Class and so i get syntax errors
http://developer.android.com/reference/android/content/Intent.html
I am attempting to spawn a service this way,
startService(new Intent(getApplicationContext(), MyService.class));
but my service never executes.
public class MyService extends IntentService {
public MyService() {
super("MyService");
}
@Override
protected void onHandleIntent(Intent intent) {
//do stuff
}
}
how can i spawn a service?
ANSWER: my android manifest didnt specifcy package
Upvotes: 0
Views: 365
Reputation: 137272
Actual problem (as found in comments) added here :
The service was in a different package, so in the manifest it has to be fully qualified, e.g. <service android:name="actual.package.of.MyService"/>
Old Answer:
If you try to launch the service in an inner class, you should not write:
startService(new Intent(this, MyService.class));
But:
startService(new Intent(ActivityName.this, MyService.class));
Make sure your service appears in the manifest.
onHandleIntent
to see whether it starts or not.Upvotes: 2
Reputation: 346
Services are not something visible
Possibly you have not declared the service in manifest file.
I dont think there is any problem with the code. Override onstartCommand and oncreate method and just put a log statement and check logcat
Upvotes: 0