fragment发送广播
Intent intent = new Intent(MainActivity.ACTION_ITEMVIEW_LISTCLICK);
intent.putExtra("position", position);
LocalBroadcastManager.getInstance(getActivity()).sendBroadcast(intent);
主界面注册接收广播
private void initBroadcastListener() {
mBroadcastManager = LocalBroadcastManager.getInstance(this);
IntentFilter intentFilter = new IntentFilter();
intentFilter.addAction(ACTION_ITEMVIEW_LISTCLICK);
mItemViewListClickReceiver = new BroadcastReceiver()
{
@Override
public void onReceive(Context context, Intent intent)
{
if(intent.getAction().equals(ACTION_ITEMVIEW_LISTCLICK))
{
Log.v(TAG, ACTION_ITEMVIEW_LISTCLICK + "," + intent.getIntExtra("position", -1));
}
}
};
mBroadcastManager.registerReceiver(mItemViewListClickReceiver, intentFilter);
}