天天看点

Android Bundle简介

Android Bundle简介

image.png

Bundle

Bundle经常使用在Activity之间或者线程间传递数据,传递的数据可以是boolean、byte、int、long、float、double、string等基本类型或它们对应的数组,也可以是对象或对象数组。

Bundle经常与Intent一起用。

例如:

Bundle bundle = new Bundle();
Intent intent=new Intent(MainActivity.this,Main2Activity.class);
//设置数据
String name="zhangSan";
String num="88888";
//把数据保存到Bundle里  
bundle.putString("name", name);
bundle.putString("num",num);
//把bundle放入intent里  
intent.putExtra("Message",bundle);
startActivity(intent);           

复制

Bundle操作基本数据类型的表格如下:

Android Bundle简介

image.png

Intent

Intent是一种运行时绑定(runtime binding)机制,它能在程序运行的过程中连接两个不同的组件。

参考

Android 意图(Intent)和过滤器(Filter)