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是從什麼地方來的。