Serializable序列化
只需要继承Seriablizable这个接口即可
person.java
自定义的对象,用来被intent传输
public class person implements Serializable {
private String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
MainActivity.java
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
person p = new person();
p.setName("小明");
Intent intent = new Intent("secondactivity");
intent.putExtra("person_data", p);
startActivity(intent);
}
}
secondactivity.java
person p = (person) getIntent().getSerializableExtra("person_data");
Log.e("name", p.getName());
Parcelable
将自定义的对象进行拆分,拆成每个部分intent都支持传输即可
网友评论