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?
Each activity in an application goes through its own lifecycle. Once and only once when an activity is created, is the onCreate() function executed.
OnCreate is only called once.
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.
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.
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"/>
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