OnCreate of android service not being called
I want to start the service in a static way. Therefore, from my activities, I call
SpeechActivationService.makeStartServiceIntent(
this.getApplicationContext(),
"WordActivator");
Here is the actual class that comes out of the service class http://dpaste.com/hold/928115/ As you can see there are several log points for example. in the onCreate method.
It is not logged. Only if I put the log text in the method makeStartServiceIntent
does it appear, however not in the method onCreate
.
Here's the method makeStartServiceIntent
:
public static Intent makeStartServiceIntent(Context context,
String activationType) {
Intent i = new Intent(context, SpeechActivationService.class);
i.putExtra(ACTIVATION_TYPE_INTENT_KEY, activationType);
return i;
}
In the manifest file I have
<service android:name="root.gast.speech.activation.SpeechActivationService"/>
Any ideas why the service won't start?
source to share
Yours makeStartService()
just creates intention for you. You don't actually seem to be firing to start the service. try it
Intent i = SpeechActivationService.makeStartServiceIntent(this,"WordActivator");
startService(i);
Note that if it this.getApplicationContext()
works, you are most likely already inside the object Context
, so just use this
.
source to share
Apart from the fact that you are not posting any code showing startService()
, it looks like the package name of yours Service
in the manifest does not match your class SpeechActivationService
( assuming the code reference you posted is the actual one SpeechActivationService
in your project, not just the class you copied from ).
<service android:name="com.mkyong.android.SpeechActivationService"/>
source to share