开发者

Binding to service that was allready started by BroadcastReceiver creates new instance of service

My Application uses a service that is started by a BOOT_COMPLETE Broadc开发者_JS百科astReceiver like this:

public void onReceive(Context context, Intent intent) {
    context.startService(new Intent(context, MyService.class));
}

If, in an activity in my application, I try to bind to this service like this:

getApplicationContext().bindService(new Intent(getApplicationContext(), MyService.class), 
    _serviceConnection, Context.BIND_AUTO_CREATE);

a new Instance of the Service is created, allthough the first instance (created by the BroadcastReceiver) is still runnning. I logged the process IDs in the onCreate() method of the service and the first service runs in a different process than the activity, the second instance is created in the same process as the activity. I tried setting a android:process argument in the service element of the manifest (both with leading : and without), but the result stays the same.

How do I bind to the service running in a different process instead of creating a new instance in the process the activity is running in?


I can assure you, it does not. Only one instance of a particular service component is ever active at a time, no matter how many times you start or bind to it. Further, the service will only run in one process. There is no way for it to run in different processes at different times.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜