Reputation: 405
Current I have three classes: activity (A), broadcastReceiver (B) and service (C).
Assuming that A is binding to C and now, B get a new intent from system.
Can B bind to the C (exactly the same one) directly?
I find out that there is a peekService method in broadcastReceiver.
my question is can I bind the running service in broadcastReceiver?
Upvotes: 1
Views: 380
Reputation: 405
I find out that using peekService can bind the running service.
Such like
IBinder ib = peekService(context, new Intent(context,
xxxxService.class));
((xxxxService.class)ib). do anything here...
Upvotes: 0
Reputation: 10672
If you have registered your receiver dynamically with Context.registerReceiver()
then you can bind to a Service
from the onReceive
method.
However, If you have declared your BroadcastReceiver
in the manifest, then you should not bind to a Service from the onReceive()
method. You can start a Service
though - you just cannot bind to it because bindService()
is asynchronous. More details about this in the Android Dev Guide and the onReceive documentation.
Upvotes: 1