Intent 传递中 Bundle与intent.putExtra 的关系
来源:互联网 发布:union软件安卓版 编辑:程序博客网 时间:2024/04/30 03:36
有一篇文章介绍这两种东西的关系
在开发软件的过程中,遇到过这样一种情况,就是没有create bundle,但是当你使用intent.putExtra之后,在另一个被call的activity中,会有bundle被传递过去,
原因就是因为intent.putExtra时,系统会检测有没有bundle,如果没有,则新建一个。所以下面这两个语句的等效的:
1
- Intent intent = new Intent(this,xxx.class);
- intent.putExtra("test", true);
- startActivity(intent);
2
- Intent intent = new Intent(this,xxx.class);
- Bundle bundle = new Bundle();
- bundle.putBoolean("test", true);
- intent.putExtras(bundle);
- startActivity(intent);
- Intent intent = new Intent();
- intent.putExtra("test_value", "TEST_V");
- Bundle bundle = new Bundle();
- bundle.putString("test_value", "TEST_V");
- intent.putExtras(bundle);
- Bundle bundle = this.getIntent().getExtras();
举个例子 我现在要从A界面 跳转到B界面或者C界面
这样的话 我就需要写2个Intent 如果你还要涉及的传值的话 你的Intent就要写两遍添加值的方法 那么 如果我用1个Bundle 直接把值先存里边 然后再存到Intent中 不就更简洁吗?
另外一个例子 如果我现在有 Activity A ,B ,C;
现在我要把值通过A经过B传给C
你怎么传 如果用Intent的话 A-B先写一遍 再在B中都取出来 然后在把值塞到Intent中 再跳到C 累吗?
如果我在A中用了 Bundle 的话 我把Bundle传给B 在B中再转传到C C就可以直接去了
这样的话 还有一个好处 就是在B中 还可以给Bundle对象添加新的 key - value 同样可以在C中取出来
0 0
- Intent 传递中 Bundle与intent.putExtra 的关系
- Intent 传递中 Bundle与intent.putExtra 的关系
- intent.putExtra() 和 bundle.putExtra()的区别
- Bundle和Intent.putExtra的区别
- Android 中Intent的putExtra()方法的值传递
- intent.putExtra与intent.getStringExtra
- intent与putextra
- Android 使用intent.putExtra实现Activity之间的参数传递
- Android 使用intent.putExtra实现Activity之间的参数传递
- Intent中putExtra()方法用法
- Intent中putExtra()方法用法
- Android Bundle的使用及与Intent传递参数区别
- Android Bundle的使用及与Intent传递参数区别
- 教你一招:在多个Activity之间传递对象,不用Bundle,Intent.putExtra
- 用Bundle和直接用Intent.putExtra("xx",yy)传递有什么不同
- Android中intent传递对象和Bundle的用法
- Android中intent传递对象和Bundle的用法
- Android中intent传递对象和Bundle的用法
- c# 程序编码规范
- ASP.NET运行机制原理
- jsp技术
- XAMPP for MAC 安装后MYSQL不能正常启动的解决办法
- vs2012编译使用lua 5.2静态库
- Intent 传递中 Bundle与intent.putExtra 的关系
- 牡丹江的水题们
- ZOJ 3593 One Person Game (扩展欧几里得)
- linux下安装nginx
- Leetcode 74 Search a 2D Matrix 有序二维数组二叉查找
- Spring3学习笔记之(spring core之DI配置使用1)
- CSU 1607: Do You Have The Template?(树链剖分)边权
- 整理牛人看文献的方法
- 研究生、科研人员须知的文献管理软件及一个学术会议网站