privateReceiveBroadCast receiveBroadCast; //广播实例
publicclassRegisteLinster implements OnClickListener
{
@Override
publicvoidonClick(View view)
{
// 注册广播接收
receiveBroadCast =newReceiveBroadCast();
IntentFilter filter =newIntentFilter();
filter.addAction(flag); //只有持有相同的action的接受者才能接收此广播
registerReceiver(receiveBroadCast, filter);
}
}
publicclassReceiveBroadCast extends BroadcastReceiver
{
@Override
publicvoidonReceive(Context context, Intent intent)
{
//得到广播中得到的数据,并显示出来
String message = intent.getStringExtra("data");
txtShow.setText(message);
}
}
|