EasyShow中getExtras()报错null

来源:互联网 发布:数据库 接口构件 编辑:程序博客网 时间:2024/06/05 10:44
源码: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是从什么地方来的。



原创粉丝点击