Android Bundle

作者: AlanGuo | 来源:发表于2016-10-18 11:45 被阅读117次

    根据 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);  
    

    相关文章

      网友评论

        本文标题:Android Bundle

        本文链接:https://www.haomeiwen.com/subject/cittuttx.html