第二个后台服务无法启动

时间:2014-04-08 14:05:28

标签: android android-service

我为我的应用定义了两个后台服务。但只有其中一个,AttachService启动。在LogCat中,我可以看到attachService的起始日志消息,但是没有来自PenManagerService的消息。我为每个服务定义了一个启动接收器

public class StartupCompletedReceiver extends BroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent intent) {
        Intent service = new Intent(context, PenManagerService.class);
        context.startService(service);

    }

}

public class AttachmentStartupReceiver extends BroadcastReceiver {

    private static final String TAG = AttachmentStartupReceiver.class.getSimpleName();


    @Override
    public void onReceive(Context context, Intent intent) {
        Log.d(TAG, "onReceive");

        Intent attachSvc = new Intent(context, AttachService.class);
        context.startService(attachSvc);

    }

}

这里是清单中两个服务的定义

   <service
        android:name="de.android.services.PenManagerService"
        android:process=":PenManagerService" >
    </service>

    <service
        android:name="de.android.services.AttachService"
        android:icon="@drawable/loading_icon"
        android:label="@string/attachServiceName"
        android:process=":attachServiceBackground" />


    <receiver
        android:name="de.android.services.StartupCompletedReceiver"
        android:process=":PenManagerService" >
        <intent-filter>
            <action android:name="android.intent.action.BOOT_COMPLETED" />
        </intent-filter>
    </receiver>
    <receiver
        android:name="de.android.AttachmentStartupReceiver"
        android:process=":attachServiceBackground" >
        <intent-filter>
            <action android:name="android.intent.action.BOOT_COMPLETED" />
        </intent-filter>
    </receiver>

两个服务都扩展了IntentService,在他们的onCreate中我有一条日志消息,但只有来自attachService的消息显示在日志中。

0 个答案:

没有答案
相关问题