开发者社区 问答 正文

我的广播为什么传不过去数据

我是新手尽量写的详细点谢谢
发数据

private void gotoWalletPay() {
 Intent intent = new Intent();
 intent.setAction("com.haihang.huanlehui.pay.util");
 intent.putExtra("price", price);
 sendOrderedBroadcast(intent, null); 
 WalletPayUtils.pay(this);

接收数据

public class WalletPayUtils {

private static String price;
public void onReceive(Context context, Intent intent) {

    price=intent.getStringExtra("price");  

} 

xml文档

<receiver android:name=".WalletPayUtils">
        <intent-filter android:priority="1000"> 
              <action android:name="com.haihang.huanlehui.pay.util"/>  
     </intent-filter>
    </receiver>

展开
收起
爵霸 2016-06-12 08:52:36 1920 分享 版权
1 条回答
写回答
取消 提交回答
  • 先看下 是不是WalletPayUtils没有继承BroadcastReceiver 要不 就用动态注册 直接在pay()中:

    IntentFilter filter = new IntentFilter();
     filter.addAction("com.haihang.huanlehui.pay.util");
     context.registerReceiver(receiver, filter);
    2019-07-17 19:33:08
    赞同 展开评论
问答分类:
问答地址: