//發(fā)送廣播的類
LocalBroadcastManager localBroadcastManager;
/**
* 發(fā)送廣播
*/
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;
/**
* 注冊(cè)廣播
*/
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);
}
}
}