机器人服务的onCreate不叫 [英] onCreate of android service not called

查看:117
本文介绍了机器人服务的onCreate不叫的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在一个静态的方式启动服务。所以从我的活动我称之为

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

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

下面是从服务类 http://dpaste.com/hold/928115/ <扩展了实际的类/ A>正如你可以看到有几个日志点,比如在onCreate方法。

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.

这是不记录。只有当我把登录 makeStartServiceIntent文本的方法它的出现,但不是在的onCreate 方法。

This is not logged. Only if I put log text in makeStartServiceIntent method it appears, however not in the onCreate 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;
}

在清单文件我有

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

为什么不启动该服务的任何想法?

Any ideas why the service is not started?

推荐答案

makeStartService()仅仅是创建一个Intent你。你似乎没有真正被发射的意图关闭以启动该服务。试试这样

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);

请注意,如果 this.getApplicationContext()工作,你很可能已经是上下文对象的内部单纯用应该的工作也。

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

这篇关于机器人服务的onCreate不叫的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆