开发者

Binding to a local Service from a BroadcastReceiver

开发者 https://www.devze.com 2023-01-16 09:32 出处:网络
My application has the following components: 2 Activities A Service and a BroadcastReceiver Whenever the us开发者_如何转开发er updates the system time, my broadcast receiver receives the Intent.ACTIO

My application has the following components:

2 Activities

A Service 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:

  1. by static definition at AndroidManifest.xml file ( link text ) )
  2. you can register receiver in the code context.registerReceiver(your_receiver, new IntentFilter(Intent.ACTION_TIME_CHANGED));
0

精彩评论

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

关注公众号