我有以下代码在我的应用程序中创建基本配置文件,它包含另一个类的对象,该类包含数组中的所有用户性能数据和各种其他原始数据类型。我如何在这个类中实现parcelable接口,以便我可以将用户配置文件对象传递给我的应用程序中的各种活动,以供读取或写入?我是否必须在Performance类和此Profile类中实现parcelable接口?
public class Profile {
private String name;
private String email;
private Performance Progress;
private int seed;
private int LastRevisionQuestion = 0;
private int[] LastQuestionQuizLinear = {0,0,0};
private int[] tempScoreQuizLinear = {0,0,0};
private int[] LastQuestionQuizRandom = {0,0,0};
private int[] tempScoreQuizRandom = {0,0,0};
private int[] LastQuestionTimedQuizLinear = {0,0,0};
private int[] tempScoreTimedQuizLinear = {0,0,0};
private int[] tempTotalTimeTimedQuizLinear = {0,0,0};
private int[] LastQuestionTimedQuizRandom = {0,0,0};
private int[] tempScoreTimedQuizRandom = {0,0,0};
private int[] tempTotalTimeTimedQuizRandom = {0,0,0};
/**
* Default constructor
*/
public Profile(){
this("ProfileName", "ProfileEmail");
}
/**
* Overloaded constructor takes user name and email address as input parameter to create a new user
* @param name
* @param email
*/
public Profile(String name, String email){
this.name = name;
this.email = email;
setProgress(new Performance());
}
}
答案 0 :(得分:1)
您只能包含简单数据类型(int,String,boolean等),parcelables
和map
。是的,您最好的选择是在parcelable
中实施Performance
。