Android

Android Bundle

2016-10-18  本文已影响117人  AlanGuo

根据 Google Android 官方文档:
“A mapping from String values to various Parcelable types.”

Bundle 可以理解为是一个 HashMap,可以向里面存取 key-value pair。

两个activity之间的通讯可以通过将Bundle对象加入 Intent 来实现:

(1)新建一个bundle类

Bundle myBundle = new Bundle();   

(2)bundle类中加入数据(key -value的形式,另一个activity里面取数据的时候,就要用到key,找出对应的value)

myBundle.putString("Data", "data from TestBundle");  

(3)新建一个intent对象,并将该bundle加入这个intent对象

Intent intent = new Intent();    
intent.setClass(TestBundle.this, Target.class);    
intent.putExtras(myBundle);  
上一篇下一篇

猜你喜欢

热点阅读