5

I want to start a service in a static way. So from my activity I call

SpeechActivationService.makeStartServiceIntent(
               this.getApplicationContext(),
               "WordActivator");

Here is the actual class that extends from service class http://dpaste.com/hold/928115/ As you can see there are several log points, e.g. in the onCreate method.

This is not logged. Only if I put log text in makeStartServiceIntent method it appears, however not in the onCreate method.

Here's the makeStartServiceIntent method:

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 manifest file I have

<service android:name="root.gast.speech.activation.SpeechActivationService"/>

Any ideas why the service is not started?

dmon
  • 30,048
  • 8
  • 87
  • 96
DarkLeafyGreen
  • 69,338
  • 131
  • 383
  • 601

2 Answers2

12

Aside from you not posting code showing startService(), it looks like the package name of your Service in the manifest doesn't match your SpeechActivationService class (assuming the code link you posted is the actual SpeechActivationService class in your project, and not just a class you copied from).

<service android:name="com.mkyong.android.SpeechActivationService"/>
Steven Byle
  • 13,149
  • 4
  • 45
  • 57
9

Your makeStartService() just creates an Intent for you. You don't seem to actually be firing that intent off to start the service. Try like this

Intent i = SpeechActivationService.makeStartServiceIntent(this,"WordActivator");
startService(i);

Note that if this.getApplicationContext() works you are likely already inside of a Context object so simply using this should work also.

FoamyGuy
  • 46,603
  • 18
  • 125
  • 156