此方法不用在manifests中注冊(cè)廣播
代碼如下:
broadcastManager = LocalBroadcastManager.getInstance(getActivity());
IntentFilter intentFilterupDateCourse = new IntentFilter();
intentFilterupDateCourse.addAction("android.intent.action.upDateCourseShow");
upDateCourse = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent){
showWeek = intent.getIntExtra("month", weekNumber);
showCorse(showWeek);
}
};
broadcastManager.registerReceiver(upDateCourse, intentFilterupDateCourse);
注冊(cè)完成后切記要在onDestroy()方法中反注冊(cè)廣播
broadcastManager.unregisterReceiver(upDateCourse);