Bundle 究竟是什么?

bundle用于场景:

在我印象中比较深刻的是,一般用于activity之间传递数值,也用于handler发送消息,如下:

Intent intent = new Intent();
        Bundle bundle = new Bundle();
        bundle.putString("KEY", "VALUE");
        intent.putExtra("bundle", bundle);
        intent.setClass(this, Other.class);
        startActivity(intent);
Bundle bundle = new Bundle();
        bundle.putString("KEY", "VALUSE");
        Message msg = new Message();
        msg.what = 1;
        msg.obj = bundle;
        Handler handler = new Handler();
        handler.sendMessage(msg);
以上2个例子可以看出来Bundle其实是一个陈放信息的容器,有点像我们存储消息的xml文件一样,也是一个key对应一个value ,然后被被intent或者msg进行传递。

那么既然是一个容器,我们怎么传递和去出呢,bundle提供了很多类型的getXXX()及setXXX()的方法。下面是盗的另外一位博主的图片啦,希望不要怪我。~^_^





發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章