首先定义一个本地广播
private LocalBroadcastManager mLocalBroadcastManager;
实例化
mLocalBroadcastManager = LocalBroadcastManager.getInstance(this);
发送方:
Intent intent = new Intent(加识别字符);//类似于intent里传递消息的识别符
intent.putExtra("path", file.getAbsoluteFile().toString());
mLocalBroadcastManager.sendBroadcast(intent);
接收方:
broadcastReceiver=new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals( 识别符)){
}
}
};
还要注册广播:
IntentFilter intentFilter=new IntentFilter();
intentFilter.addAction(SHOWIMAGE_BROADCAST_ACTION);
mLocalBroadcastManager.registerReceiver(broadcastReceiver,intentFilter);
网友评论