正统方法
- 单行数据
// 传值
Intent intent = new Intent(this, KapHomePageActivity.class);
intent.putExtra("homePageActivity_name","小明");
// 取值
Intent intent = getIntent();
String name = intent.getStringExtra("homePageActivity_name");
- 多行数据
// 传值
Intent intent = new Intent(this, KapHomePageActivity.class);
Bundle bundle = new Bundle();
bundle.putString("name","小明");
bundle.putInt("age",21);
intent.putExtra("homePageActivity_bundle",bundle);
// 取值
Intent intent = getIntent();
Bundle bundle = intent.getBundleExtra("homePageActivity_bundle");
String name = bundle.getString("name");
int age = bundle.getInt("age");
- 对象(需要将对象进行序例化: Serializable)
// 序列化对象
public abstract class KapModelBase implements Serializable{ // 实现序列化接口,用于页面间传递对象
}
// 传值
Intent intent = new Intent(this, KapHomePageActivity.class);
intent.putExtra("homePageActivity_modelBill", new KapModelBill());
// 取值
Intent intent = getIntent();
KapModelBill bill = (KapModelBill)intent.getSerializableExtra("homePageActivity_modelBill");
- 数组 (数组元素要实现Parcelable接口)
// 传值
Intent intent = new Intent(this, KapHomePageActivity.class);
intent.putParcelableArrayListExtra("homePageActivity_modelArray", new ArrayList<KapModelBill>());
// 取值
Intent intent = getIntent();
ArrayList<KapModelBill> modelList = intent.getParcelableArrayListExtra("homePageActivity_modelArray");