EasyShow中getExtras()报错null

源码:Activity A: :Intent intent = new Intent(Setting.this,EasyShow.class); 
                                 Bundle Bundle = new Bundle(); 
                                 Bundle.putInt("1s",0);
                                 intent.putExtra("b",Bundle); 

                                 startActivity(intent);

          Activity B:    Intent intent = this.getIntent();
                             intent.getBundleExtra("b").getInt("1s")//报错:nullpointer

解释: api:     getExtras() the map of all extras previously added with putExtra(), or null if none have been added.// a map of extended data?没懂。。那个英语好点的解释一下,(*^__^*) 嘻嘻……
                      putExtras( Intent src)   Copy all extras in 'src' in to this intent.
                      putExtras( Bundle extras)  Add a set of extended data to the intent.//因为是all,a set of,所以用Extras。。
                      putExtra ( String  name,  Bundle  value)    Add extended data to the intent.

Intent.getExtras()这个函数获得的Bundle是通过Intent.putExtra(.. , ..)这种函数放入的数值的Bundle,
而我是直接放的一个自己的Bundle进去

解决:putExtra("b",bundle)

           getBundleExtra("name")//的到的Bundle就通过name与放进去的一一对应了。

意思就是说,intent里面的东西不只有Bundle,还有其他的?

同时,还要注意,你的intent是从什么地方来的。



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值