Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

onCreate of android service not called

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?

like image 257
UpCat Avatar asked Feb 14 '13 14:02

UpCat


People also ask

When onCreate function is called in Android?

Each activity in an application goes through its own lifecycle. Once and only once when an activity is created, is the onCreate() function executed.

Is onCreate only called once?

OnCreate is only called once.

How many times is onCreate called?

OnCreate will only be called one time for each lifetime of the Activity. However, there are a number of situations that can cause your activity to be killed and brought back to life. Thus, onCreate will be called again.

What does onCreate mean?

Android App Development for Beginners onCreate() is called when the when the activity is first created. onStart() is called when the activity is becoming visible to the user.


1 Answers

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"/>
like image 179
Steven Byle Avatar answered Oct 18 '22 22:10

Steven Byle