您的位置:首页 > 其它

在Activity之间使用Intent传值和Bundle传值的区别和方式

2015-12-27 03:06 435 查看
两者本质上没有任何区别。
Bundle只是一个信息的载体 将内部的内容以键值对组织
Intent负责Activity之间的交互 自己是带有一个Bundle的
Intent.putExtras(Bundle bundle)直接将Intent的内部Bundle设置为参数里的bundle
Intent.getExtras()直接可以获取Intent带有的Bundle

intent.putExtra(key, value)

Bundle bundle = intent.getExtras();
bundle.putXXX(key, value);
intent.putExtras(bundle);
是等价的

intent.getXXXExtra(key)

Bundle bundle = intent.getExtras();
bundle .getXXX(key);
是等价的(XXX代表数据/对象类型 String boolean 什么的)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: