首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >没有从sendBroadcast接收Extras

没有从sendBroadcast接收Extras
EN

Stack Overflow用户
提问于 2014-04-01 15:40:03
回答 1查看 335关注 0票数 0

我有一个MainClass,它注册一个BroadcastReceiver并重写它的onReceive()方法

代码语言:javascript
复制
        BroadcastReceiver broadcastReceiver=new BroadcastReceiver(){
        @Override
        public void onReceive(Context context,Intent intent){
            Log.w("MyApp","RICEVUTO MESSAGGIO BROADCAST: "+intent.getStringExtra("com.example.avis.NUOVANEWS"));
            Log.w("MyApp","Intent TOSTRING "+intent.toString());


        }

    };
    this.getApplicationContext().registerReceiver(broadcastReceiver,  new IntentFilter("nuovanewsavis"));

在NewsService类中,当发现新消息时,我广播了一条新消息。这是密码

代码语言:javascript
复制
              Intent intento=new Intent("nuovanewsavis");
          intent.setAction("nuovanewsavis");
          intent.putExtra("com.example.avis.NUOVANEWS", "Nuova notizia");

          this.sendBroadcast(intento);

MainClass无法获得额外的信息:如果我试图通过getStringExtra读取它,就会得到一个null。我做错什么了吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-04-01 15:43:37

我认为有一个typo...your使用的是intent,而不是intento

代码语言:javascript
复制
      Intent intento = new Intent("nuovanewsavis");
      intento.setAction("nuovanewsavis");
      intento.putExtra("com.example.avis.NUOVANEWS", "Nuova notizia");

      this.sendBroadcast(intento);
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/22790552

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档