浅析android中的Bundle类
Bundle的介绍是这样的:A mapping from String values to various Parcelable types
类继承关系:
java.lang.Object
android.os.Bundle
Bundle类是一个final类:
public final class Bundle extends Objectimplements Parcelable Cloneable
直接说用法吧:
1、一个A类直接传值:
Bundle bundle = new Bundle();
bundle.putString("key", "value");
Intent intent = new Intent(A.this, B.class);
intent.putExtras(bundle);
startActivity(intent);
另一个B类接收
Bundlebundle=getIntent().getExtras();
Stringdata=bundle.getString("key");
2、主要介绍的用法,传序列化的对象(个人感觉挺好用,但是不知道有什么局限性)
一个A类传对象
首先对象要实现接口
public class C implements Serializable{}
C c = new C();
Bundle bundle = new Bundle();
bundle bundle.putSerializable("key", C); (此时会将C对象的所有属性方法传到下一个类中)
Intent intent = new Intent(A.this, B.class);
intent.putExtras(bundle);
startActivity(intent);
另一个B类接收对象C c;
c = getIntent().getSerializableExtra("key");(A类中的属性方法传给了B类)
无意中看到,感觉在实际开发中挺实用的一个类,可能还有其他方法,感觉比较笨重
更多相关文章
- 一个hello程序的android内核模块编译方法及在模拟器中进行测试结
- Android实现计时与倒计时(限时抢购)的几种方法(线程)
- Android 获取网络图片方法
- android 字符串转换成JSON对象
- android 游戏 Canvas 常用方法
- Android 保留两位小数点的4种方法