BaseActivity中: ReceiverDialog rd; rd = new ReceiverDialog(); updataUI()中可以传入参数,也可以根据这个参数来判断,那个页面的数据要更新 public void updataUI(){//int updataUI //发送广播(注册广播) Intent intentupdataUI = new Intent(); intentupdataUI.setAction("com.cardvalue.sys.activitys.BasicLimit"); //intentupdataUI.putExtra("updataUI",updataUI); this.sendBroadcast(intentupdataUI); }
//广播的类
public class ReceiverDialog extends BroadcastReceiver { private ReceiverUI receiverUi; public interface ReceiverUI{ void onReceive(); } @Override public void onReceive(Context context, Intent intent) { receiverUi.onReceive(); } public void setReceiveUI(ReceiverUI receiverUi){ this.receiverUi = receiverUi;}}<span style="font-family: Arial, Helvetica, sans-serif;"> </span>
<pre code_snippet_id="1626356" snippet_file_name="blog_20160328_4_9929761" name="code" class="java"><span style="font-family: Arial, Helvetica, sans-serif;"></span><pre code_snippet_id="1626356" snippet_file_name="blog_20160328_4_9929761" name="code" class="java">//activity中使用的时候
private ReceiverDialog rd ; rd=new ReceiverDialog();<span style="font-family: Arial, Helvetica, sans-serif;">IntentFilter filter = new IntentFilter();filter.addAction("com.cardvalue.sys.activitys.BasicLimit"); //只有持有相同的action的接受者才能接收此广播registerReceiver(rd, filter);rd.setReceiveUI(new ReceiverUI() {@Overridepublic void onReceive() { //这个里面写要更新的东西 }}</span>
activity中使用的时候 也就是发送广播的时候 ,只需要调用updataUI()就可以了