从另一个服务启动服务

Starting service from another service

我正在尝试从另一个服务启动一个服务。但是想知道出了什么问题。代码就像

class Service1 extends GCMBaseIntentService {

    @Override
    protected void onMessage(Context arg0, Intent intent) {
        Toast.makeText(getApplicationContext(), "Hello", Toast.LENGTH_LONG).show();
        Intent service = new Intent(getApplicationContext(), Service2.class);
        startService(service);
    }
}

而 Service2 是

class Service2 extends Service {

    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
        // TODO Auto-generated method stub
        Toast.makeText(getApplicationContext(), "Service Started", Toast.LENGTH_LONG).show();
    }
}

我在 Service1 中获取了 Toast "Hello",但没有从 Service2

中获取 Toast "Service Started"

您应该使用 Service1.thisgetBaseContext() 而不是 getApplicationContext() 。您是否在 AndroidManifest 中声明了您的 Service2?