//发送广播的类
LocalBroadcastManager localBroadcastManager;
/**
* 发送广播
*/
public void SendMyBroadCast(String id, Context context) {
localBroadcastManager = LocalBroadcastManager.getInstance(context);
Intent broadIntent = new Intent("com.text.id");
broadIntent.putExtra("id",id);
localBroadcastManager.sendBroadcast(broadIntent);
}
//接收广播的类
IntentFilter intentFilter;
BroadReceiver localReceiver;
LocalBroadcastManager localBroadcastManager;
/**
* 注册广播
*/
public void registerBroad() {
localBroadcastManager = LocalBroadcastManager.getInstance(getContext());
intentFilter = new IntentFilter();
intentFilter.addAction("com.text.id");
localReceiver = new BroadReceiver ();
localBroadcastManager.registerReceiver(localReceiver, intentFilter);
}
/**
* 广播接收者
*/
class BroadReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals("com.text.id")) {
cid = intent.getStringExtra("id");
mHandler.sendEmptyMessage(1);
}
}
}