首页 > 移动平台 > 详细

Android中定义广播监听,其他页面发送

时间:2019-08-29 10:05:07      阅读:151      评论:0      收藏:0      [点我收藏+]

  private LocalBroadcastManager broadcastManager; /** * 注册广播接收器 */ private void receiveAdDownload() { broadcastManager = LocalBroadcastManager.getInstance(getActivity()); IntentFilter intentFilter = new IntentFilter(); intentFilter.addAction("fresh_user_info"); //监听的事件key broadcastManager.registerReceiver(mAdDownLoadReceiver, intentFilter); //调用广播回调方法 } //调用广播回调方法 BroadcastReceiver mAdDownLoadReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { Utils.Log("收到了广播:"+mAdDownLoadReceiver); Bundle bundle = intent.getExtras(); String resource = bundle.getString("resource"); //Intent 取值,发送广播时候传递的 Utils.Log("resource:"+resource); //执行自己的业务逻辑...... } }; //发送广播 可以在其他页面发送 Intent intents = new Intent("fresh_user_info"); //发送的目标 intents.putExtra("resource", "add");       //发送的数据  LocalBroadcastManager.getInstance(UserProfileSettingActivity.this).sendBroadcast(intents);

  

Android中定义广播监听,其他页面发送

原文:https://www.cnblogs.com/pxjbk/p/Android.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!