• 用Broadcast广播在activity之间、fragment之间、activity和fragment之间相互传数据


    例如:A界面要收到B界面的更变信息

    一、A界面注册广播

    private static final String INTENT_BROADCAST = "android.intent.action.MEDICAL_BROADCAST";// 广播跳转意图

    LocalBroadcastManager broadcastManager = LocalBroadcastManager.getInstance(getActivity());
                IntentFilter intentFilter = new IntentFilter();
                intentFilter.addAction(INTENT_BROADCAST);
                BroadcastReceiver bordcastReceiver = new BroadcastReceiver() {

                     @Override
                    public void onReceive(Context context, Intent intent) {
                          //信息处理

                          Toast.makeText(context, "信息更新", Toast.LENGTH_SHORT).show();             

                    }
               };
      broadcastManager.registerReceiver(bordcastReceiver, intentFilter);

    二、B界面发送广播通知A界面改变信息

    Intent broadcast = new Intent(INTENT_BROADCASTS);

    LocalBroadcastManager.getInstance(this).sendBroadcast(broadcast);

  • 相关阅读:
    个人作业——软件工程实践总结作业
    BETA答辩总结
    beta冲刺7
    beta冲刺6
    beta冲刺5
    beta冲刺4
    beta冲刺3
    华为云
    beta冲刺2
    beta冲刺1
  • 原文地址:https://www.cnblogs.com/qianyukun/p/6097796.html
Copyright © 2020-2023  润新知