Binding to a service that has already been started by BroadcastReceiver creates a new instance of the service

My application uses a service launched using BOOT_COMPLETE BroadcastReceiver, for example:

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

If in action in my application, I try to bind this service as follows:

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

a new instance of the Service is created, although the first instance (created by BroadcastReceiver) is still running. I registered process identifiers in the onCreate () method of the service and the first service starts in a different process than the action, the second instance is created in the same process as the activity. I tried to set the android: process argument in the manifest service element (both with and without the host), but the result remains the same.

How do I bind a service running in another process, instead of creating a new instance of the process in which the action is performed?

+4
source share
1 answer

I can assure you this is not so. Only one instance of one service component is always active at a time, regardless of how many times you start or contact it. In addition, the service will work in only one process. It is not possible to run it in different processes at different times.

0
source

All Articles