[英]onCreate of android service not called
我想以静态方式启动服务。 所以从我的活动中我打电话
SpeechActivationService.makeStartServiceIntent(
this.getApplicationContext(),
"WordActivator");
以下是从服务类http://dpaste.com/hold/928115/扩展的实际类。正如您所看到的,有几个日志点,例如在onCreate方法中。
这不会被记录。 只有当我在makeStartServiceIntent
方法中放入日志文本时,它才出现,但不在onCreate
方法中。
这是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;
}
在清单文件中我有
<service android:name="root.gast.speech.activation.SpeechActivationService"/>
有没有为什么服务没有开始的想法?
除了您没有发布显示startService()
代码之外,看起来清单中Service
的包名称与您的SpeechActivationService
类不匹配( 假设您发布的代码链接是项目中的实际SpeechActivationService
类,而不仅仅是你复制的课程 )。
<service android:name="com.mkyong.android.SpeechActivationService"/>
你的makeStartService()
只是为你创建一个Intent。 您似乎并没有实际启动该服务。 试试这样吧
Intent i = SpeechActivationService.makeStartServiceIntent(this,"WordActivator");
startService(i);
请注意,如果this.getApplicationContext()
有效,则您可能已经在Context
对象中,因此使用this
也应该可以正常工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.