weixin_42218038
随缘56
采纳率100%
2019-05-08 15:46

android 广播接收不到消息怎么处理?

5

发送消息是Activity,接收消息是Fragment,回到调用Fragment的activity并没有接收到

Intent intent1=new Intent("android.intent.action.CART_BROADCAST");
 intent1.putExtra("login", s);   
sendBroadcast(intent1);
 BroadcastReceiver receiver;
    LocalBroadcastManager broadcastManager;
         receiver = new BroadcastReceiver() {
            public void onReceive(Context context, Intent intent) {
                String s= intent.getExtras().getString("login");
                login.setText("1234");
            }
        };
        broadcastManager = LocalBroadcastManager.getInstance(getActivity());
        IntentFilter intentFilter = new IntentFilter();
        intentFilter.addAction("android.intent.action.CART_BROADCAST");
        broadcastManager.registerReceiver(receiver, intentFilter);

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

1条回答

为你推荐