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


  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);

  

转载于:https://www.cnblogs.com/pxjbk/p/Android.html

你可能感兴趣的:(Android中定义广播监听,其他页面发送)