Sending and receiving broadcast messages enables inter activity communication. Suppose in activity A you have completed a task and you want activity B to react accordingly, then broadcasting helps a lot. A only needs to initialize an intent and send it via a broadcast message. B needs to set a filter to get the specific messages from A and register a receiver, where the actions upon receving messages are defined. 

In activity A, the message can be sent this way

Intent broadcastI=new Intent();broadcastI.setAction("edu.hkust.cse.phoneAdapter.ruleChange");sendBroadcast(broadcastI);

In activity B, the filter and receiver
IntentFilter filter=new IntentFilter("edu.hkust.cse.phoneAdapter.ruleChange");this.registerReceiver(new BroadcastReceiver() {        @Override    public void onReceive(Context arg0, Intent arg1) {        Toast.makeText(getApplicationContext(), "msg received", Toast.LENGTH_SHORT).show();    }},filter);

Easy, right?


更多相关文章

  1. 代码中设置drawableleft
  2. android 3.0 隐藏 系统标题栏
  3. Android开发中activity切换动画的实现
  4. Android(安卓)学习 笔记_05. 文件下载
  5. Android中直播视频技术探究之—摄像头Camera视频源数据采集解析
  6. 技术博客汇总
  7. android 2.3 wifi (一)
  8. AndRoid Notification的清空和修改
  9. Android中的Chronometer

随机推荐

  1. android 完美获取状态栏高度
  2. android整合--屏幕旋转触发事件
  3. Android获取应用程序的信息
  4. Android自定义属性,format详解
  5. Android笔记【外观部分】
  6. [Android] View动画特效(三)
  7. android添加开机声音
  8. Android(安卓)file.createNewFile方法问
  9. Android(安卓)打开系统蓝牙设置
  10. Android(安卓)启动 Launcher