我在写入和读取类型为 Class<? extends Activity>
的变量时遇到问题但我可以找到任何解决方案。
clas为变量名,类型为Class<? extends Activity>
。当学生单击列表 Activity 时,我使用此变量打开相关 Activity
没有像 Parcelable.readClass()
这样的函数或writeClass()
谁能帮忙解决这个问题
提前致谢
这是我的Student.java
public class Student {
private String id;
private Class<? extends Activity> clas;
...
}
在这里我创建了ParcalebleStudent.java
public class ParcalebleStudent implements Parcelable {
private Student student;
....
private ParcalebleStudent(Parcel in) {
student = new Student();
student.setId(in.readString());
student.setClas(in.readWhat?????????);//I need help here
}
@Override
public void writeToParcel(Parcel parcel, int flags) {
parcel.writeString(student.getId());
parcel.writeWhat???????(student.getClas());//and here
}
}
最佳答案
您可以使用 parcel.writeString(student.getClas().getName());
和 student.setClas(Class.forName(in.readString());
关于Android:如何使用类<?扩展 Activity> 作为 Parcelable 中的变量类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20623138/