LocalBroadcastManager

LocalBroadcastManager用于发送接收那些只用于本app内部组件的Broadcast。

可以用于IntentService向启动它的组件发送结果


在IntentService中发送broadcast:

LocalBroadcastManager.getInstance(context).sendBroadcast(intent);


在另一侧接收broadcast,注册receiver:

LocalBroadcastManager.getInstance(context).registerReceiver(receiver,filter);

LocalBroadcastManager.getInstance(context).registerReceiver(receiver,filter2); //在原来的receiver上追加新的filter


broadcast不会start或者resume Activity,activity的receiver收到broadcast后可以在后台处理,在onReceiver方法中不要启动activity。


LocalBroadcastManager_第1张图片


你可能感兴趣的:(LocalBroadcastManager)