Bundle类
来源:互联网 发布:wifi热点软件 编辑:程序博客网 时间:2024/05/16 02:56
Bundle类
Bundle类是一个key-value对,两个activity之间的通讯可以通过bundle类来实现。
Bundle传递数据
1、实现步骤:
a、在一个类中:
Bundle mBundle = new Bundle();//新建一个bundle类
mBundle.putString("key", "value");
//bundle类中加入数据(key -value的形式,另一个activity里面取数据的时候,就要用到key,找出对应的value)
Intent intent = new Intent();//新建一个intent对象
intent.setClass(activity_1.this, activity_2.class);
intent.putExtras(mBundle); //将该bundle加入这个intent对象
startActivity(intent);
b、在另一个类中:
Bundle bundle = getIntent().getExtras(); //得到传过来的bundle
String data = bundle.getString("Data");//读出数据
2、思路:
(key,vlaue)--->Bundle--->intent-->Bundle-->通过key找到vlaue
Bundle传递对象
一种是Bundle.putSerializable(Key,Object);另一种是Bundle.putParcelable(Key, Object);当然这些Object是有一定的条件的,前者是实现了Serializable接口,而后者是实现了Parcelable接口
方式一:Bundle.putSerializable(Key,Object);
Bundle data = new Bundle();
data.putSerializable("data", 对象比如ArrayList);
List<Map<String , String>> list =
(List<Map<String , String>>)data.getSerializable("data");
//此方法在activity中之间传递List或者map数据集合对象的时候有用
方式二:Bundle.putParcelable(Key, Object);
- Bundle类
- Bundle类
- Bundle类
- Bundle类
- Bundle类
- Bundle类加载器
- Android Bundle类
- Android Bundle类
- Android Bundle类
- Android Bundle类
- Android Bundle类笔记
- Android Bundle类
- bundle通信----类访问
- Android Bundle类 学习
- Android Bundle类
- Android Bundle类
- Android Bundle类
- Android Bundle类
- PHP通过iconv将字符串从GBK转换为UTF8字符集
- ASP.NET如何输出刷新父窗口脚本语句
- Java编程时值得注意的地方
- IOS-使用UiTableview模仿UICollectionView的效果
- 解析IOS崩溃日志(crash Log)
- Bundle类
- 从 Flash 到 Cocos2d-x
- Create custom framework with XCode 6.1.1
- 20150130 【 ARM 】 数据结构+顺序链表+GDB
- 【Qt5开发及实例】25、实现代理的功能
- mac下删除svn文件
- log4j简介
- Windows 2D绘图引擎的发展及联系
- 获取HttpURLConnection 响应体内容