Serializable是序列化的意思,表示将一个对象转换成可存储或可传输的状态。序列化后的对象可以在网络上进行传输,也可以存储到本地.序列化的方法很简单,实现Serializable接口就可以了.
1.比如有个Person类
public class Person implements Serializable{
private String name;
private int age;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
}
接下来在FirstActivity使用就非常简单了
```java
Person person = new Person();
person.setName("Tom");
person.setAge(18);
Intent intent = new Intent(FirstActivity.this, SecondActivity.class);
intent.putExtra("person1",person);
startActivity(intent);
在SecondActivity取出对象
//序列化对象向下转型为Person对象
Person person=(Person)getIntent().getSerializableExtra("person1");