Binding to a local Service from a BroadcastReceiver
My application has the following components:
2 Activities AService
and a
BroadcastReceiver
Whenever the us开发者_如何转开发er updates the system time, my broadcast receiver receives the Intent.ACTION_TIME_CHANGED
. Now when this happens I want to reschedule a Handler
in my Service
. How do I bind to a Service within my BroadcastReceiver
?
Your service can catch the intent directly without any BroadcastReceiver help.
Can be done by adding intent-filter to your service. There are two ways to do that:
- by static definition at AndroidManifest.xml file ( link text ) )
- you can register receiver in the code context.registerReceiver(your_receiver, new IntentFilter(Intent.ACTION_TIME_CHANGED));
精彩评论