考虑到Android架构并考虑Android的操作设计,如意图,视图,活动,内容提供商等等,有人可以向我解释什么样的"事物"是可以包含的还是捆绑的?在Android网站上写的解释对我来说听起来有点过于蹩脚,我的意思是阅读"一个特殊的类型安全容器,称为Bundle,可用于异构值的键/值映射." 我对Bundles一无所知,对我来说,它们可以是XML文件,哈希映射,以及"键/值映射"的所有其他变体.
什么是Parcelable或Bundle,他们的设计是什么以及他们做了什么?
谢谢.
Kin*_*uoc 10
Parcelable并且Bundle是您想要与意图一起发送的信息包!
Bundle如果你想开始新的activity就可以发送Bundle信息给activity与沿new Intent您创建:
// Bundle b is sent with new intent i
Bundle b = new Bundle();
b.putString(key, value);
b.putInt(key, value);
Intent i = new Intent(...);
i.putExtras(b);
startActivity(i);
// In the activity which started from the intent i, you can get the bundle b
this.getIntent().getExtras();
Run Code Online (Sandbox Code Playgroud)
Parcelable是interface,如果你想传递一个object(你自己的类)用bundle或intent,你应该实现这个interface:
class Example implements Parcelable{
// some information here
}
// You can send with intent or bundle:
b.putParcelable(key, value);
i.putExtra(name, value);
Run Code Online (Sandbox Code Playgroud)
谷歌android的更多细节:Bundle Parcelable
| 归档时间: |
|
| 查看次数: |
4497 次 |
| 最近记录: |