android记25:aidlService使用
Android笔记:aidlService的实现
AIDL:android Interface Definition Language
服务端的实现:
实体类Student、ClassName,需要继承Parcelable接口,并复写主要方法
(注意复杂类型变量的使用方法)
/**
* 实现android自己的序列化接口
*
* @author Administrator
*
*/
public class Student implements Parcelable {
private int id;
private String name;
public Student() {
super();
}
public Student(int id, String name) {
super();
this.id = id;
this.name = name;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@Override
public int describeContents() {
return 0;
}
/**
* 序列化
*/
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeInt(id);
dest.writeString(name);
}
/**
* 反序列化
*/
public final static Parcelable.Creator CREATOR = new Creator() {
@Override
public Student createFromParcel(Parcel source) {
// 与上述的write顺序一致
return new Student(source.readInt(), source.readString());
}
@Override
public Student[] newArray(int size) {
return new Student[size];
}
};
}
//
public class ClassName implements Parcelable {
private Student student;
private List students;
public ClassName() {
super();
this.student = new Student(0, "班长");
List students = new ArrayList();
students.add(new Student(1, "t1"));
students.add(new Student(2, "t2"));
this.students = students;
}
public Student getStudent() {
return student;
}
public void setStudent(Student student) {
this.student = student;
}
public List getStudents() {
return students;
}
public void setStudents(List students) {
this.students = students;
}
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeParcelable(student, flags);